Reputation: 8637
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!"];
}
Upvotes: 0
Views: 1065
Reputation: 58067
To fix this problem, change
action:@selector(buttonAction:)
To
action:@selector(buttonAction)
For general debugging, try readin Apple debugging guide, which can be found here: http://developer.apple.com/library/ios/#documentation/DeveloperTools/Conceptual/XcodeDebugging/000-Introduction/Introduction.html
You are going to want learn about using the debugger (Cmd +Shift + Y) and the console, accessible with the keyboard shortcut, Cmd +Shift + R.
Good luck!
Upvotes: 0
Reputation: 75073
If you are a beginner, you should start with a tutorial or better, a good book about the subject.
You can output a message to the console using NSLog(@"My variable value: %@", myVariable);
You can use Debugging, line by line, just add a breakpoint anywhere in the code and Run as Debug.
Upvotes: 1
Reputation: 1080
Alt+Click "Build & Run" button to debug. Click "Show console" button. Use NSLog and breakpoints. Try declaring: -(void) buttonAction:(id) sender;
Upvotes: 1
Reputation: 6856
Try this.
In all seriousness, apple has a fairly decent guide for debugging using XCode.
Upvotes: 0
Reputation: 170809
action:@selector(buttonAction:)
Here you specify that buttonAction selector gets 1 parameter, but it is declared to have none:
- (void)buttonAction{
...
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
action:@selector(buttonAction)
or change action method declaration:
- (void)buttonAction:(id)sender{
...
Upvotes: 3