Ios 以编程方式创建UITableViewController时使用情节提要
我想使用我在序列图像板中创建的表视图以编程方式创建UITableViewController,其中我将序列图像板命名为Ios 以编程方式创建UITableViewController时使用情节提要,ios,objective-c,uitableview,ios7,Ios,Objective C,Uitableview,Ios7,我想使用我在序列图像板中创建的表视图以编程方式创建UITableViewController,其中我将序列图像板命名为TableViewCont.storyboard 下面是我试图在AppDelegate.m中使用的代码: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSBundle *bundle = [NSBu
TableViewCont.storyboard
下面是我试图在AppDelegate.m
中使用的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSBundle *bundle = [NSBundle mainBundle];
UITableViewController *tvc = [[UITableViewController alloc] initWithNib:@"TableViewCont" bundle:bundle];
self.window.rootViewController = tvc;
return YES;
}
没有报告语法错误,但当我在设备上运行应用程序时,TableViewController不会显示。当您使用
initWithNib:bundle:
初始化时,我知道UITableViewController
的功能不同于UIViewController
,但我不明白为什么此代码不起作用…您不能在故事板中使用initWithNib。这是针对xib文件的
要从情节提要中初始化控制器,必须使用实例化eviewcontrollerwhiteIdentifier。请参见下面的示例
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"TableViewCont" bundle:nil];
UITableViewController *tvc = (UITableViewController *)[storyboard instantiateViewControllerWithIdentifier:@"your identifier"];
别忘了在情节提要中输入tableview控制器的标识符