我一直在按照本教程设置带有故事板的桌面视图。
一切正常,除了在本教程开始时他以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会显示,但其中没有数据。
干杯杰夫
答案 0 :(得分:1)
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
这里,代码是获取窗口的根视图控制器,它来自原始项目是一个标签栏控制器。你已经删除了这个,所以这将返回一个导航控制器。
您已从视图控制器层次结构中删除了一定程度的包含。您的根视图控制器现在是导航控制器。所以,我认为你需要的代码是:
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
AlbumViewController *albumsViewController = [[navigationController viewControllers] objectAtIndex:0];
albumsViewController.albums = albums;