如何告诉 UIViewController UIPopOverController 中的按钮被按下?

发布于 2024-11-04 04:19:00 字数 137 浏览 7 评论 0原文

我认为标题是不言自明的。 我有一个 UIPopOverController,其中是一个表格视图,当我选择一个单元格时,我想告诉它 UIViewController。

有一个简单的解决方案还是我需要 KeyValueObserving 或通知?

i think the title is self explaining.
I have an UIPopOverController, in it is a tableview and when i select a cell, i want to tell it the UIViewController.

Is there an easy solution or do i need KeyValueObserving or notifications?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

忆依然 2024-11-11 04:19:00

从 tableview 发布 NSNotification 并将 UIViewController 添加为观察者。

Post an NSNotification from the tableview and add the UIViewController as an observer.

不气馁 2024-11-11 04:19:00

您可以根据您的选择采用两种方法之一进行移动。

首先:使用委托/协议。
http://www.thepectiveprogrammer.com/2010/05 /objective-c-protocols-and-delegates.html

第二: 将 UIViewController 设置为 UIButton 的目标。

例如

[btn addTarget:myController action:@selector(ActionWillBePerformedInController:) forControlEvents:UIControlEventTouchUpInside];

you could move with one of two approaches as per your choice.

first : using delegate/protocol.
http://www.thepensiveprogrammer.com/2010/05/objective-c-protocols-and-delegates.html

second: Set your UIViewController as the target for your UIButton.

for example

[btn addTarget:myController action:@selector(ActionWillBePerformedInController:) forControlEvents:UIControlEventTouchUpInside];
勿忘初心 2024-11-11 04:19:00

发布 NSNotification 效果很好...您还可以在 UITableViewController 类中创建回调对象和选择器。

您可以使用回调对象和回调选择器初始化 UITableViewController

initWithTarget:(id)theTarget andSelector:(SEL) theSelector

...将值保存到属性,

然后从 tableView 中的 didSelectRowAtIndexPath ...调用

[self.target performSelector:self.selector];

使用此方法,您可以根据需要定义自己的回调方法...从您的创建弹出窗口的 ViewController 类,你可以做这样的事情......

[[MyTableView alloc] initWithTarget:(self) andSelector:@selector(popoverControllerDidRequestClose)];

Posting an NSNotification will work well... you can also create a callback object and selector in your UITableViewController class.

you could initialize your UITableViewController with a callback object and callback selector

initWithTarget:(id)theTarget andSelector:(SEL) theSelector

...save off the values to properties

then from the didSelectRowAtIndexPath in your tableView... call

[self.target performSelector:self.selector];

using this methodology, you can define your own callback methods as you wish.. from your ViewController class that created the popover, you could do something like this...

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