我是新來的代表和選擇器的概念與通知一起使用。所以我的第一個問題是,調用委託方法和調用選擇器
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];
}
很抱歉,如果這些基本問題。我不確定這種事情的最佳做法是什麼,並希望開始正確的方式。謝謝。