为什么我的方法不能完全发挥作用? (iPhone SDK)
我的代码中有一个方法:
-(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:redButton 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];
}
}
出于某种原因, NSLog 调用确实有效并显示在控制台上。该按钮一开始显示“开始录制”,但按下它不会执行任何操作,即使它与 Interface Builder 中的“Touch Up Inside”相关联以调用此方法并被引用。
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:redButton 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题是这一行:
您正在比较指针,而不是字符串。您需要:
Your problem is this line:
There you're comparing pointers, not strings. You need: