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
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: