更改此根视图设置
我一直在遵循本教程来设置带有故事板的表格视图。
一切正常,除了在教程的开头,他从 tabBarView 模板开始,并在其中嵌入了 UINavigationControl。
这就是他提出的代码 - 有效:
UITabBarController *tabBarController =
(UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController =
[[tabBarController viewControllers] objectAtIndex:0];
AlbumViewController *albumsViewController =
[[navigationController viewControllers] objectAtIndex:0];
albumsViewController.albums = albums;
这是其中的一部分:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
albums = [NSMutableArray arrayWithCapacity:5];
Album *album1 = [[Album alloc] init];
Album *album2 = [[Album alloc] init];
Album *album3 = [[Album alloc] init];
Album *album4 = [[Album alloc] init];
Album *album5 = [[Album alloc] init];
album1.albumName = @"Graduation";
album2.albumName = @"Dark and Twisted Fantasy";
album3.albumName = @"Torches";
album4.albumName = @"Nothing But The Beat";
album5.albumName = @"Angles";
album1.artist = @"Kanye West";
album2.artist = @"Kanye West";
album3.artist = @"Foster The People";
album4.artist = @"David Guetta";
album5.artist = @"The Strokes";
album1.rating = 5;
album2.rating = 5;
album3.rating = 5;
album4.rating = 5;
album5.rating = 5;
[albums addObject:album1];
[albums addObject:album2];
[albums addObject:album3];
[albums addObject:album4];
[albums addObject:album5];
UITabBarController *tabBarController =
(UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController =
[[tabBarController viewControllers] objectAtIndex:0];
AlbumViewController *albumsViewController =
[[navigationController viewControllers] objectAtIndex:0];
albumsViewController.albums = albums;
// Override point for customization after application launch.
return YES;
}
这部分发布在 AppDelegate.m 中 我真的正在尝试一切,但没有任何效果。
任何帮助都会很棒:-)
PS 如果我取出 tabView 或注释掉第一段代码,TableView 会显示,但其中没有数据。
干杯杰夫
I have been following this tutorial to set up a tableview with storyboarding.
It's all working, except in the beginning of the tutorial he starts with a tabBarView template and he embeds a UINavigationControl in that.
So this is the code that he comes up with - which works:
UITabBarController *tabBarController =
(UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController =
[[tabBarController viewControllers] objectAtIndex:0];
AlbumViewController *albumsViewController =
[[navigationController viewControllers] objectAtIndex:0];
albumsViewController.albums = albums;
Which is part of:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
albums = [NSMutableArray arrayWithCapacity:5];
Album *album1 = [[Album alloc] init];
Album *album2 = [[Album alloc] init];
Album *album3 = [[Album alloc] init];
Album *album4 = [[Album alloc] init];
Album *album5 = [[Album alloc] init];
album1.albumName = @"Graduation";
album2.albumName = @"Dark and Twisted Fantasy";
album3.albumName = @"Torches";
album4.albumName = @"Nothing But The Beat";
album5.albumName = @"Angles";
album1.artist = @"Kanye West";
album2.artist = @"Kanye West";
album3.artist = @"Foster The People";
album4.artist = @"David Guetta";
album5.artist = @"The Strokes";
album1.rating = 5;
album2.rating = 5;
album3.rating = 5;
album4.rating = 5;
album5.rating = 5;
[albums addObject:album1];
[albums addObject:album2];
[albums addObject:album3];
[albums addObject:album4];
[albums addObject:album5];
UITabBarController *tabBarController =
(UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController =
[[tabBarController viewControllers] objectAtIndex:0];
AlbumViewController *albumsViewController =
[[navigationController viewControllers] objectAtIndex:0];
albumsViewController.albums = albums;
// Override point for customization after application launch.
return YES;
}
This part is posted in the AppDelegate.m
I am really trying everything, but nothing works.
Any Help would be great:-)
PS If I take out the tabView or comment out the first bit of code, the TableView shows, but there is no data in it.
Cheers Jeff
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这里,代码正在获取窗口的根视图控制器,该控制器在原始项目中是一个选项卡栏控制器。您已删除它,因此这将返回一个导航控制器。
您已从视图控制器层次结构中删除了一个包含级别。您的根视图控制器现在是导航控制器。所以,我认为你需要的代码是:
Here, the code is getting the root view controller of the window, which from the original project was a tab bar controller. You have removed this, so this will be returning a navigation controller.
You've removed a level of containment from the view controller hierarchy. Your root view controller is now a navigation controller. So, I think the code you need is: