2011-12-14 72 views
0

我一直在關注本教程以設置與故事板的桌面視圖。更改此根視圖設置

這一切都工作,除了在教程開始時,他開始與一個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

什麼不行?你看不到什麼,你希望看到? – jrturton 2011-12-14 09:56:55

+0

所以基本上我想根據教程設置一個UITableView與應用程序委託中的數據,但我不想用TabBarController開始。所以基本上就像它在那裏一樣,但是如果你看看代碼的第一部分,它會將TabBar設置爲根控制器 - 但是隻要我觸及並更改它,就會丟失表中的數據。 – 2011-12-14 10:00:45

回答

1
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; 

這裏,代碼是獲得窗口,它從原始項目是標籤欄控制器的根視圖控制器。你已經刪除了這個,所以這將返回一個導航控制器。

您已從視圖控制器層次結構中移除了一定程度的限制。你的根視圖控制器現在是一個導航控制器。所以,我認爲你需要的代碼是:

UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController; 
AlbumViewController *albumsViewController = [[navigationController viewControllers] objectAtIndex:0];   
albumsViewController.albums = albums;