【问题标题】:Getting a return value from a button's action method从按钮的操作方法中获取返回值
【发布时间】:2014-10-16 15:45:15
【问题描述】:

我有一个按钮,我在代码中设置了一个动作:

[buttonOk addTarget:self action:@selector(check:) forControlEvents:UIControlEventTouchUpInside];

check: 方法返回一个int。我怎样才能收到这个int

【问题讨论】:

    标签: objective-c cocoa-touch uibutton ibaction


    【解决方案1】:

    创建一个调用check: 的不同方法。让这个方法处理返回值。

    - (void)mymethod:(id)sender {
      int value = [self check:sender];
      // use your value or send it somewhere
    }
    

    【讨论】:

      【解决方案2】:

      函数check返回int,我怎样才能收到这个int?

      An action method should have IBAction as its return type,而IBAction 定义为void。你可以从 action 方法中调用任何你想要的方法,但是 action 本身不应该返回任何东西。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-12
        • 1970-01-01
        • 2020-03-02
        相关资源
        最近更新 更多