How do I debug an iPhone aplication? How can I find out what’s going on in the simulator? I’m a beginner in Xcode development and don’t know what’s the problem with the code below. The app is crashing on button click.
- (void)viewDidLoad {
myLabel = [[UILabel alloc]init];
[myLabel setText:@"Labela"];
myLabel.frame = CGRectMake(50.0,50.0, 100.0, 30.0);
[self.view addSubview:myLabel];
myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[myButton addTarget:self
action:@selector(buttonAction:)
forControlEvents:UIControlEventTouchDown];
[myButton setTitle:@"Klikni" forState:UIControlStateNormal];
[myButton setFrame:CGRectMake(80.0, 210.0, 160.0, 40.0)];
[self.view addSubview:myButton];
[super viewDidLoad];
}
- (void)buttonAction {
[myLabel setText:@"Promijenjen!"];
}
Here you specify that buttonAction selector gets 1 parameter, but it is declared to have none:
So when button click system tries to call undefined method and that results in crash. To fix that you should either change selector name to
or change action method declaration: