ABPeoplePicker 委托模式问题

发布于 2024-08-22 20:04:42 字数 423 浏览 8 评论 0原文

我有一个子类 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹雪碎 2024-08-29 20:04:43

基本上,你有一些状态,你会问它属于哪里,对吧?不幸的是,答案是“这实际上取决于国家”。

如果它与视图控制器的操作有关,我会说把它放在那里并保留视图控制器作为委托。

如果它并不是真正相关,并且整个委托可以移动到一个单独的对象中,那么最终可能会更干净。获得数百行长、数十种方法的噩梦控制器真的很容易。将事物分成多个对象并使用组合模式非常有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文