是否有相当于“焦点监听器”的东西?在 Objective-C 或 iPhone SDK 中? (来自爪哇)
我是一名学生程序员,我在空闲时间学习了 Objective-C,因为我的大学不教授它。到目前为止我们只使用过 Java 和基本的 C。我正在为 iPod 编写一个程序,想知道是否有任何类型的方法可以像 Java 中的 Focus Listener 那样调用类中的方法?我有一个视图,当视图放置在顶部并再次可见时,我想调用刷新方法(以更新从另一个视图新输入的按钮标题)。这是否太简单了,还是有更系统的方法来做到这一点?我尝试从其他视图类调用该方法,但它似乎不起作用(表示另一个类未定义或可能不接受方法调用并在执行时崩溃)。
任何见解将不胜感激。感谢您抽出时间。
I am a student programmer who has taken up Objective-C on my free time as my college doesn't teach it. We have only used Java and basic C so far. I am in the middle of making a program for the iPod and was wondering if there was any type of way to call a method in a class similar to the way a Focus Listener does in Java? I have a view that I would like to call a refresh method (to update the newly inputted titles of buttons from another view) when the view is put at the top and visible again. Is this too easy or is there a more methodical way of doing that? I have tried to just call the method from the other view class but it does not seem to work (says the other class is either undefined or may not accept the method call and crashes on execution).
Any insight would be appreciated. Thank you for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道我是否很好地理解了这个问题,但是当视图可见时,会在 UIViewController 中调用“viewDidAppear:”方法。
否则,NSNotification 相当于 Objective-C 中的监听器模式。你可以像这样添加一个观察者:
被观察者像这样处理他的消息:
I don't know if I have understood the issue very well but when a view is being visible the "viewDidAppear:" method is call in the UIViewController.
Otherwise the equivalent of the Listener pattern in Objective-C is the NSNotification. You can add an Observer like that:
And the Observed handled his message like that: