为什么我的方法不能完全发挥作用? (iPhone SDK)

发布于 2024-08-21 12:53:02 字数 1614 浏览 11 评论 0原文

我的代码中有一个方法:

-(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪落纷纷 2024-08-28 12:53:02

您的问题是这一行:

if (actionButton.titleLabel.text == @"Begin Recording"){

您正在比较指针,而不是字符串。您需要:

if ([actionButton.titleLabel.text isEqualToString:@"Begin Recording"]){

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"]){
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文