开发者

TableView on Tab Bar Application ? Application is crashing

开发者 https://www.devze.com 2022-12-22 13:08 出处:网络
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\"

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 T开发者_StackOverflowableView 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 ?


In Interface Builder, after you've updated the NIB Name to Table, click on the Identity tab of the inspector (the last tab). Then updated the Class Identity to 'Table'.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号