开发者

How can you tell an UIViewController that a button is pressed in an UIPopOverController?

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 te开发者_开发百科ll it the UIViewController.

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


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


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];


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)];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜