3

我正在学习 Objective-C 和 iOS 开发。我想我掌握了方法语法。Objective C 中的方法语法

如果我理解正确,这个名为 reset 的实例方法应该返回一个 IBAction 对象。但它似乎只是在设置实例变量(它们是具有这些名称的 UI 文本字段)。为什么它没有返回 IBAction 对象的 return 语句?

- (IBAction)reset {               //why does it not have a return statement?
    fahrenheit.text = @"32";
    celsius.text = @"0";
    kelvin.text = @"-273.15";
}

我习惯了看起来像这样的 .NET 代码(将其放入非 NET 人员的伪代码中):

public function reset () returns IBAction
        me.fahrenheit.text = "32";
        me.celsius.text = "0"
        me.kelvin.text = "-273.15"
        return new IBAction    //I would expect something like this in obj C, based on my experience with .NET languages
end function
4

1 回答 1

8

IBAction 是 typedef 无效的。Xcode 使用它作为提示,该方法可用于接口构建器中的“连接”。

于 2012-10-14T15:16:18.637 回答