繁体   English   中英

如何将UIViewController从使用此视图的不同UIViewController的单独UIView推入UINavigationController

[英]How to push UIViewController into UINavigationController from seperate UIView of different UIViewController which uses this view

我有一个带有NavigationControllerUIViewControllerAbcViewController )。 AbcViewController使用UIView( AbcView )作为其视图。 AbcView有一个UITableView 我已经在AbcViewController设置了此TableView的数据源,并在其SuperView中进行了委托,即AbcView 当我在此表中选择一行时,如何将另一个UIViewControllerXyzViewcontroller )推入navigationController

“错误:请求成员'navigationController'的原因不是结构或联合”

当我这样做时:

[self.navigationController pushViewController:xyzViewcontroller animated:TRUE]; 

我也这样做了:

AbcViewController *parentVC;
[parentVC.navigationController pushViewController:xyzViewcontroller animated:TRUE]; 

尽管构建成功,但不会出现XyzViewcontroller的视图。 它不会将XyzViewcontroller的视图推送到navigationController上。

我们可以在AbcView上创建一个委托,以便可以返回到视图的viewController,在本例中为AbcViewController 我们可以将委托设置为:

@interface AbcView : UIView

{ 
    id delegate;
}

@property(nonatomic, assign) id delegate;

然后在AbcViewController ,像这样设置视图的委托:

[abcView setDelegate:self];

现在在表格方法中,使用AbcView中的代理作为:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   [delegate pushOtherView];

}

它将在AbcViewController调用- (void)pushOtherView方法,其定义为:

- (void)pushOtherView 
{   
    XyzViewcontroller * xyzViewcontroller = [[[XyzViewcontroller alloc] init] autorelease];
   [self.navigationController pushViewController:xyzViewcontroller animated:YES];   
}

但是在使用此方法之前,应该在协议中提及它,否则它将显示

警告:

-pushOtherView”未在协议中找到。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM