Joris Dijkstra
Joris Dijkstra

Reputation: 132

UITableView in UInavigationController not working

enter image description hereI have been searching and experimenting on this for a while, but I just can't find out what I'm doing wrong.

I want to make an app with a menu, and from that menu, you can get to a TableViewcontroller with a title bar. I found out that, in order to get this title bar, you need to "insert" UITableViewController into a UINavigationController. this is where I'm stuck.

let's not mind / forget the menu from the app for now, because i know how to switch view controllers when user taps a button.

in my AppDelegate.m I have:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    TableViewController *tableView = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
    self.navController = [[UINavigationController alloc] initWithRootViewController:tableView];
    self.window.rootViewController = navController;
    [self.window makeKeyAndVisible];
    return YES;
}

in my AppDelegate.h file I Have:

@interface AppDelegate : UIResponder <UIApplicationDelegate>{
    UINavigationController *navcontroller;
}

@property (strong, nonatomic) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;

I have 2 classer, UITableViewController and NavigationView.

In the UITableViewController, I made an array called tableRows:

tableRows = [[NSArray arrayWithObjects:@"1", @"2", nil] init];

the numberOfSectionsInTableView is set as 1 and the numberOfRowsInSection is set as return tableRows.count;

I left my NavigationView.m untouched, except that I tried to set a title in it.

in my NavigationView.xib, I tried to make the connection between the UITableViewController and the UINavigationController.

Now my problem is, with or without the connections in IB, whatever I try to change in my table, or in the titlebar, it does not change when I run the app.

Does anybody know what I'm doing wrong? I'm using xcode 4.6, so lots of the tutorials I've checked are not very useful, because they are made with older versions of xcode. please help me, Thank you in advance!

Upvotes: 0

Views: 1289

Answers (3)

Dipen Panchasara
Dipen Panchasara

Reputation: 13600

enter image description herein you AppDelegate replace this line

    TableViewController *tableView = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];

with this

    TableViewController *tableView = [[TableViewController alloc] initWithStyle:UITableViewStylePlain];

Upvotes: 1

Matt
Matt

Reputation: 2411

You might also find it very useful to checkout the free Sensible TableView framework. The framework will take your array and automatically generate all the table view cells, while managing all the details required to correctly setup the navigation controller. Hope this helps.

Upvotes: 0

Carl Veazey
Carl Veazey

Reputation: 18363

You're not creating an instance of TableViewController but instead UITableViewController so thus you're not getting any of your code executed. (You should have a compiler warning for this in your app delegate - make sure to heed those warnings). Likewise you're not loading the NavigationView nib anywhere - you're creating a navigation controller with the table as the root view controller. It's not clear what your objective for NavigationView is so I can't provide a recommendation for how to proceed. However, for the table view, change the following line in your app delegate

TableViewController *tableView = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];

to

TableViewController *tableView = [[TableViewController alloc] init];

In your table view xib, make sure File's Owner's class is set to be of class TableViewController (not UITableViewController). Right click on the table view and drag the circles next to 'data source' and 'delegate' to file's owner. Then right click file's owner and make sure the circle next to 'view' is connected to the table view. Save, clean, and run.

Upvotes: 0

Related Questions