我一直在为此苦苦挣扎一段时间,在网上筛选解决方案,但还没有设法到达那里,所以我想是时候问问你们了。我有一个标签栏应用程序,我在其中尝试使用包含表格视图(TableViewController
)的导航控制器根据按下的单元格切换到不同的视图。
当触摸表格视图中的单元格时,我的SecondViewController
被加载(这是我通过在viewDidLoad()
方法中为背景着色来检查的),但是界面(XIB
)没有加载,因此窗口是空白的(或在我的背景测试的情况下着色)。窗口(SecondViewController
)应该包含一个在直接访问视图时起作用的UIScrollerView
。我应该提到,所有视图控制器都包含在单个XIB
文件中,XIB
文件包含选项卡栏控制器和应用程序委托所需的空白窗口(窗口和tabBarController
)。
这就是我从TableViewController.m
切换视图的方式(navigationController
的rootViewController
)
SecondViewController *viewSecond = [SecondViewController alloc];
self.secondViewController = viewSecond;
[self.navigationController pushViewController:self.secondViewController animated:YES];
这是appDelegate.m
applicationDidFinishLaunchingWithOptions()
// Set the tab bar controller as the window's root view controller and display.
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
tabBarController.moreNavigationController.navigationBar.hidden = YES;
return YES;
这实际上是一个旧项目的后续项目,所以我现在确定为什么XIB
中需要空白窗口(如果这与问题有任何关系),因为它在模板标签栏应用程序中不需要。我才刚刚开始iOS开发,所以如果我在任何地方含糊不清,我深表歉意。任何帮助将不胜感激。
在你的TableViewController.m
中,你错过了init
你的SecondViewController
。只是调用alloc
不会从笔尖加载。
因此,SecondViewController *viewSecond = [SecondViewController alloc];
更改为SecondViewController *viewSecond = [[SecondViewController alloc] init];
或SecondViewController *viewSecond = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];