Sto provando a creare un pulsante, che una volta toccato mostrerà un popover di un altro UIView. Per testare il tutto, ho il seguente codice nella mia sezione viewDidLoad:Codice codice UIButton azione
- (void)viewDidLoad
{
[super viewDidLoad];
self.hard1 = [UIButton buttonWithType:UIButtonTypeCustom];
[self.hard1 setFrame:CGRectMake(884, 524, 105, 60)]; // set the x,y,width and height based on your specs
UIImage *buttonImage = [UIImage imageNamed:@"green.jpg"];
hard1.layer.cornerRadius = 10;
hard1.clipsToBounds = YES;
[hard1 addTarget: self
action: @selector(buttonClicked:)
forControlEvents: UIControlEventTouchUpInside];
[self.hard1 setImage:buttonImage forState:UIControlStateNormal];
[self.view addSubview:self.hard1];
}
e più in basso:
- (IBAction) buttonClicked: (id)sender
{
NSLog(@"Tap");
}
tuttavia, la console non registra 'Tap' quando premo il tasto. Qualche idea?
Ah, stupido. Grazie mille! –
Ora che ci sono. Quando si crea una proprietà, eseguire questa operazione in sintetizzare: @synthesize hard1 = _hard1; In questo modo il riferimento alla proprietà come solo "hard1" non funzionerà. È self.hard1 o _hard1 (quest'ultimo solo da utilizzare nel metodo setter) – Odrakir
grazie mille per il vostro aiuto –