gpt4 book ai didi

iphone - 轻按 UIBarButtonItem 时未调用操作

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:10:25 24 4
gpt4 key购买 nike

注意:我只在模拟器上测试过。

我想在代码中添加目标操作,而不是在 Interface Builder 中将其连接为 IBAction。

theButton 在左上角的导航栏上,在 IB 中创建。

步骤:

  1. theButton 声明为 IBOutlet 并在 IB 中连接它。

  2. viewDidLoad 中添加:

    self.theButton.target = self;
    self.theButton.action = @selector(theAction);
  3. 我正在通过此测试 theAction:

    - (void)theAction {
    NSLog(@"theAction called");
    //do some other stuff
    }

当我在模拟器中点击 theButton 时,没有任何反应。我根本没有看到 NSLog 语句。

我错过了什么?

最佳答案

您是否已将操作连接到界面构建器中的按钮?

如果不是,您应该在 .h 文件中声明该操作

-(IBAction)theAction;

更改 .m 文件上的操作名称

-(IBAction)theAction{

}

然后将操作精细地连接到界面构建器中的按钮。

关于iphone - 轻按 UIBarButtonItem 时未调用操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6407242/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com