我有一个方法,它应该初始化导航控制器并为侧面菜单加载视图控制器。这一切都发生在未连接到任何其他导航控制器的视图控制器中。
- (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]时它才有用。但即便如此,我也无法让导航控制器推送任何其他视图控制器。
请帮助。
答案 0 :(得分:0)
没关系,我找到了一些东西,我使用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];
}
像魅力一样工作