【问题标题】:Using UIPopOver to navigate a different view使用 UIPopOver 导航不同的视图
【发布时间】:2011-04-14 07:18:31
【问题描述】:

所以我有一个名为“TopNewsViewController”的 ViewController 类。它从 RootViewController 被推送到 NavigationController 堆栈中。

在 TopNewsViewController 中,我有一个通过单击按钮出现的弹出窗口。它显示来自 PopOver 的表格视图。

现在,在 PopOver 的 tableView:didSelectRowAtIndexPath 方法中,我希望它修改 TopNewsViewController 的一些属性并重新推送到导航堆栈。我正在实现该方法如下:

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

我意识到这不起作用,因为我使用的是“self.navigationController”,而 PopOver 不是 ViewController,而是 UITableViewController。我尝试改用“topNewsViewController.navigationController”,但没有成功。

有人对如何实现它有任何建议吗?非常感谢您的帮助/建议!

【问题讨论】:

    标签: objective-c cocoa-touch ipad uipopover


    【解决方案1】:

    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.然后 RootViewController 将处理推送和弹出您想要使用的任何新 TopNewsViewControllers。您在此处创建的新 TopNewsViewController 默认没有导航控制器,这就是它不起作用的原因。

    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) .

    【讨论】:

    • 哦 - 你是对的。但是我将如何将我的 RootViewController 实现为“代表”?只需在我的弹出视图控制器中实例化一个 RootViewController 对象吗?像这样:RootViewController *rootViewController = [[RootViewController alloc] initWithNib....?
    • 所以我在 popoverviewcontroller 中创建了这个:@protocol PopOverDelegate <NSObject> @required - (void)didSelectRow:(NSUInteger)row; @end 和 tableView:didSelectRowAtIndexPath: 在我的实现中:NSUInteger rowNumber = [indexPath row]; [[self delegate] didSelectRow:rowNumber]; [tableView deselectRowAtIndexPath:indexPath animated:YES]; 但是 didSelectRow 没有被调用(做了一些调试)。我是否错误地创建了协议?
    • 您是否将根视图控制器设置为弹出表视图控制器的委托?
    • 我一直在尝试这样做。我知道它的 something.delegate = self。但我把它放在哪里?它会在 RootviewController 中吗?我应该创建一个弹出表视图控制器的实例,如 PopOverViewController *popOverViewController = [PopOverViewController alloc] 等....然后 popOverViewController.delegate = self;在 Root ViewController 的 ViewDidLoad 中?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-26
    • 2011-07-29
    • 2016-08-06
    • 1970-01-01
    相关资源
    最近更新 更多