Why isn't my method fully working? (iPhone SDK)
I have a method here that is in my code:
-(IBAction) actionButtonPressed: (id) sender{
NSLog(@"%@",actionButton.titleLabel.text);
if (actionButton.titleLabel.text == @"Begin Recording"){
[actionButton setTitle:@"Finish Recording" forState:UIControlStateNormal];
[actionButton setTitle:@"Finish Recording" forState:UIControlStateApplication];
[actionButton setTitle:@"Finish Recording" forState:UIControlStateHighlighted];
[actionButton setTitle:@"Finish Recording" forState:UIControlStateReserved];
[actionButton setTitle:@"Finish Recording" forState:UIControlStateSelected];
[actionButton setTitle:@"Finish Recording" forState:UIControlStateDisabled];
UIImage *redButton = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bigredbutton" ofType:@"png"]];
[actionButton setBackgroundImage:redButton forState:UIControlStateNormal];
[actionButton setBackgroundImage:re开发者_高级运维dButton forState:UIControlStateApplication];
[actionButton setBackgroundImage:redButton forState:UIControlStateHighlighted];
[actionButton setBackgroundImage:redButton forState:UIControlStateReserved];
[actionButton setBackgroundImage:redButton forState:UIControlStateSelected];
[actionButton setBackgroundImage:redButton forState:UIControlStateDisabled];
}
if (actionButton.titleLabel.text == @"Finish Recording"){
[self dismissModalViewControllerAnimated:YES];
}
}
For some reason the NSLog call does work and shows up on the Console. The button starts out reading Begin Recording, yet pressing it does nothing even though it is tied up with Touch Up Inside in Interface Builder to call this method and is referenced.
Your problem is this line:
if (actionButton.titleLabel.text == @"Begin Recording"){
There you're comparing pointers, not strings. You need:
if ([actionButton.titleLabel.text isEqualToString:@"Begin Recording"]){
精彩评论