开发者

Using UIPopOver to navigate a different view

开发者 https://www.devze.com 2023-02-25 21:26 出处:网络
So I have a ViewController class called \"TopNewsViewController\". It gets pushed onto the NavigationController stack from RootViewController.

So I have a ViewController class called "TopNewsViewController". It gets pushed onto the NavigationController stack from RootViewController.

In TopNewsViewController, I have a pop over that appears by clicking a button. It displays a Table View from PopOver.

Now, in the method tableView:didSelectRowAtIndexPath in PopOver, I want it to modify some properties of TopNewsViewController and re-push it to the navigation stack. I am implementing the method as follows:

TopNewsViewController *topNewsViewController = [[[TopNewsViewController alloc] initWithNibName:@"TopNewsViewController" bundle:nil] autorelease];

NSString *feedStr = [rootViewController.feeds objectAtIndex:rowNumber];
[rootViewController release];
NSArray *thisFeed = [NSArray arrayWithObjects:feedStr, nil];
topNewsViewController.feeds = thisFeed;
topNewsViewController.pageTitle = [categories objectAtIndex:rowNumber];
[self.navigationController pushViewController:topNewsViewController animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];

I realized that this does not work because I am using "self.navigationController", when PopOver is not a ViewController, and instead is a UITableViewController. I tried doing "topNewsViewController.navigationController" instead but 开发者_C百科it did not work.

Anyone has any suggestions on how to implement it? Help/suggestions are greatly appreciated!


If I'm understanding you correctly, I think probably your best bet would be to implement a delegate in your popover's UITableViewController, such that when a record is selected, it calls the delegate method to hand back the selection to your RootViewController. The RootViewController would then handle pushing and popping whatever new TopNewsViewControllers you want to use. The new TopNewsViewController you are creating here doesn't have a nav controller by default, that's why it won't work.

So, your root view controller becomes the delegate of your popover view controller... when a row is selected, it says "popOver:didSelectRow:" and then RootViewController dismisses the popover and "does the right thing"(tm).

0

精彩评论

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

关注公众号