TableView on Tab Bar Application ? Application is crashing.

Posted by Andrei on Stack Overflow See other posts from Stack Overflow or by Andrei
Published on 2010-03-11T23:25:23Z Indexed on 2010/05/29 20:52 UTC
Read the original article Hit count: 157

Filed under:
|
|

Steps to reproduce:
1. Create a Tab Bar Application called "TestApp"
2. Add new file, a UIViewController subclass with a XIB user interface called "Table"
3. Open up MainWindows.xib, click on the Second tab bar item and in Inspector change the NIB Name from "SecondView" to "Table". Save and close.
4. Open up Table.xib and drag a TableView on top of the view. Now link the dataSource and delegate outlets of the TableView to the Table.xib File's Owner.
5. Add the following code to Table.m:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSLog(@"Returning num sections");
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"Returning num rows");
return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Trying to return cell");

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
cell.text = @"Hello";
NSLog(@"Returning cell");
return cell;
}

6.Run the application and select the Second tab bar item.

If I start with a View-based application, add a TableView to it, link the outlets to the File's owner and add that piece of code it all works just fine. What am I doing wrong ? Why is the application crashing ?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about tableview