Ios [UINavigationController setView]和[UINavigationController SetViewController]之间的差异
我有一个方法,它应该初始化一个导航控制器并为侧菜单加载一个视图控制器。这一切都发生在未连接到任何其他导航控制器的视图控制器内Ios [UINavigationController setView]和[UINavigationController SetViewController]之间的差异,ios,objective-c,uinavigationcontroller,pushviewcontroller,Ios,Objective C,Uinavigationcontroller,Pushviewcontroller,我有一个方法,它应该初始化一个导航控制器并为侧菜单加载一个视图控制器。这一切都发生在未连接到任何其他导航控制器的视图控制器内 - (void)showLeftNC { if (leftNavCon == nil) { leftNavCon = [[UINavigationController alloc] init]; } [leftNavCon setViewControllers:@[lmvc] animated:NO]; //[l
- (void)showLeftNC
{
if (leftNavCon == nil)
{
leftNavCon = [[UINavigationController alloc] init];
}
[leftNavCon setViewControllers:@[lmvc] animated:NO];
//[leftNavCon setView:lmvc.view];
[leftNavCon.view setFrame:lmvc.view.frame];
[self.view addSubview:leftNavCon.view];
[self showCenterViewWithShadow:YES withOffset:-2];
[self.view sendSubviewToBack:leftNavCon.view];
}
leftNavCon是导航控制器
lmvc是主视图控制器
它不以这种方式工作,当我调用initWithRootViewController:lmvc时也是如此
它只有在我使用注释的[leftNavCon setView:lmvc.view]时才起作用。但即使这样,我也无法让导航控制器推送任何其他视图控制器
请帮忙。没关系,我想出了一些办法,我使用lmvc作为包含视图,初始化了导航控制器以及其中所需的所有视图控制器 在lmvc initWithNibName中
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
if (testViewController == nil)
{
testViewController = [[UIViewController alloc] init];
}
if (navCon == nil)
{
navCon = [[UINavigationController alloc] initWithRootViewController: testViewController];
}
view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 748)];
[self setView:navCon.view];
[testViewController.view addSubview:table];
[testViewController.view addSubview:button];
[testViewController.view addSubview:anyControlYouNeed];
}
后来
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableTwo == nil)
{
tabl = [[UITableView alloc] initWithFrame:table.frame];
}
if (testViewControllerTwo == nil)
{
testViewControllerTwo = [[UIViewController alloc] init];
}
tableTwo.delegate = self;
tableTwo.dataSource = self;
[testViewControllerTwo setView:tableTwo];
[navCon pushViewController: testViewControllerTwo animated:YES];
}
就像一个符咒一样工作
[leftNavCon设置视图:lmvc.view]
意味着您将UINavigationController的视图设置为lmvc的视图。我猜在运行代码后,推送的viewController的视图将位于UINavigationController的视图下方。您确定[leftNavCon SetViewController:@[lmvc]已设置动画:否]代码>不工作?我总是这样做。它现在可以工作了,但是我使用了一个视图控制器作为导航控制器的容器,因为它不能单独调用来添加子视图