ABPeoplePicker 委托模式问题
我有一个子类 UIViewController,充当 ABPeoplePicker 导航控制器委托。这个视图控制器在几种不同的情况下调用这个 ABPeoplePicker,我遇到的问题是弄清楚我在
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
UIAlertView 中响应的情况具有从 UIView 继承的标记属性来帮助解决这个问题,但我找不到类似的在 ABPeoplePickerNavigationController 中使用的属性。可可忍者如何处理这种情况?剥离自定义代表?在视图控制器子类中摆弄一些布尔值?
I have a subclassed UIViewController that's acting as an ABPeoplePicker Navigation Controller Delegate. This view controller calls this ABPeoplePicker in a few different situations and the problem I'm having is figuring out which situation I'm responding to in
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
UIAlertView has the tag property inherited from UIView to help sort this out but I can't find a similar property to use in ABPeoplePickerNavigationController. How are the Cocoa ninjas handling situations like this? Spin off custom delegates? Fiddle some BOOLs in the view controller subclass?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,你有一些状态,你会问它属于哪里,对吧?不幸的是,答案是“这实际上取决于国家”。
如果它与视图控制器的操作有关,我会说把它放在那里并保留视图控制器作为委托。
如果它并不是真正相关,并且整个委托可以移动到一个单独的对象中,那么最终可能会更干净。获得数百行长、数十种方法的噩梦控制器真的很容易。将事物分成多个对象并使用组合模式非常有帮助。
Basically, you have some state, and you're asking where it belongs, right? Unfortunately, the answer is "It really depends on the state."
If it's related to the operation of the view controller, I'd say stick it in there and keep the view controller as the delegate.
If it isn't really related and the whole delegate can be moved into a separate object, that may be in the end a lot cleaner. It's really easy to get nightmare controllers that are hundreds of lines long with dozens and dozens of methods. Splitting things up into multiple objects and using the composition pattern can be really helpful.