我是新来的代表和选择器的概念与通知一起使用。所以我的第一个问题是,调用委托方法和调用选择器
1)比方说,你有一个按钮,有一个委托,实现了一些doWork
方法。如果您想要与方法中的功能相同,那么只需调用该方法是否可以?我不知道这是否被认为是良好的编码实践和/或如果你应该这样做,或者做一些不同的事情来获得这种类型的功能。如果这是好的架构?
2)同样,与NSNotificationCenter,我看到一些代码发布通知。然后有一个HandleSegmentedControl:(NSNotification *)notification
方法。如果我想手动拥有该功能,但没有按下段控制,那么只需将该功能从该方法中取出并放入新方法中即可,如下所示:OK:
- (void)HandleSegmentedControl:(NSNotification *)notification {
NSDictionary *dict = [userInfo notification];
// do stuff with the dictionary
}
新:
- (void)HandleSegmentedControl:(NSNotification *)notification {
NSDictionary *dict = [userInfo notification];
[self newMethod:dict];
}
- (void)newMethod:(NSDictionary *)dict {
// do stuff with the dictionary
}
- (void)myOtherMethodThatNeedsTheSameFunctionality {
NSDictionary *dict = // create some dictionary
[self newMethod:dict];
}
很抱歉,如果这些基本问题。我不确定这种事情的最佳做法是什么,并希望开始正确的方式。谢谢。