【问题标题】:actual difference between - (IBAction)pushClear:(id)sender and - (IBAction)pushClear:(NSButton)sender- (IBAction)pushClear:(id)sender 和 - (IBAction)pushClear:(NSButton)sender 之间的实际区别
【发布时间】:2011-09-27 09:29:35
【问题描述】:

当我将按钮链接到源代码(在本例中为 .h 文件)并选择 NSButton 作为类型时,Xcode 将写入:

- (IBAction)pushClear:(id)sender;

据我所知应该是

- (IBAction)pushClear:(NSButton)sender;

我是对的,还是只是有些困惑?如果我链接某事。在 iOS Interface Builder 中,一切似乎都在做它应该做的事情。

所以我必须手动修复这些东西吗?或者它是好的方式(最后,每件事都运行良好。只是不想在路上遇到问题。

编辑:

仅使用是否存在某种性能问题?

- (IBAction)pushClear:(id)sender; 

【问题讨论】:

标签: objective-c ios macos cocoa xcode4


【解决方案1】:

你可以这样设置类型:

- (IBAction)pushClear:(NSButton *)sender;

如果您确定,只有 NSButton 对象会发送此操作。

如果你不确定,那么你可以离开:

- (IBAction)pushClear:(id)sender;

并在此方法内部检查 sender 是否属于 NSButton 类。

【讨论】:

  • 所以最简单的方法就是将所有设置为 (id),对吧?或者它背后是否存在某种性能问题?谢谢。 - (IBAction)pushClear:(id)sender; ——
  • 在某些情况下最简单的方法是在其他情况下设置(NSButton *) (id)。试试他们两个。你可以从(NSButton *)开始我认为=)
猜你喜欢
  • 1970-01-01
  • 2014-07-31
  • 2014-03-14
  • 2016-02-09
  • 1970-01-01
  • 2011-10-30
  • 1970-01-01
  • 2014-03-21
  • 2011-02-09
相关资源
最近更新 更多