[英]How to push UIViewController with replaced UINavigationController
[英]How to push UIViewController into UINavigationController from seperate UIView of different UIViewController which uses this view
我有一个带有NavigationController
的UIViewController
( AbcViewController
)。 AbcViewController
使用UIView( AbcView
)作为其视图。 AbcView
有一个UITableView
。 我已经在AbcViewController
设置了此TableView
的数据源,并在其SuperView
中进行了委托,即AbcView
。 当我在此表中选择一行时,如何将另一个UIViewController
( XyzViewcontroller
)推入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.