every one.
I’m developing iphone app.
I try to change the Button’s title in my code.
When i click a button, then the title will change the other text.
So, i use setTitle method, but the app is killed.
The code is following.
-(IBAction)deleteProject:(id)sender{
UIButton *button = (UIButton *) sender;
if (addButton.enabled == YES ){
addButton.enabled = NO ;
//Here, the code is stopped.
[button setTitle:@"Back" forstate:UIControlStateNormal];
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[mainTableView setEditing:YES animated:YES];
}
else{
addButton.enabled = YES;
//Here, the code is stopped. V
[button setTitle:@"Delete" forstate:UIControlStateNormal];
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[mainTableView setEditing:NO animated:YES];
}
}
Please help me.
You get passed a
senderparameter into yourdeleteProject:method. This parameter is typeid, which can be anything.You cast it to
UIButtonand try to use it as aUIButton.The exception you get is
[UIBarButtonItem setTitle:forState:]This should tell you that
senderisn’t aUIButtonat all, it’s aUIBarButtonItem🙂You can test this but putting this code at the start of your
deleteProject:method.