Domanda

Come posso ancorare una funzione al mio pulsante che ho creato in questo modo

button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.titleLabel.font            = [UIFont systemFontOfSize: 12];
button.titleLabel.lineBreakMode   = UILineBreakModeTailTruncation;
button.titleLabel.shadowOffset    = CGSizeMake (1.0, 0.0);
[button addTarget:self                     
               action:@selector(aMethod:)
     forControlEvents:UIControlEventTouchDown];

button.frame = CGRectMake(80.0, 160.0, 160.0, 40.0);

[button setTitle:string forState:UIControlStateNormal]; 
[self.view addSubview:button];

lo voglio fare simile come fare IB quando mi collego una funzione a un pulsante. E 'possibile?

È stato utile?

Soluzione

Si sta facendo bene (supponendo che l'aMethod ottiene 1 parametro - il controllo dell'interfaccia utente che eventi trigger). L'unica differenza con l'azione cablata di default in IB -. È che in azione IB è impostato per l'evento UIControlEventTouchUpInside

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top