开发者

Grouped UITableView displays fine, but only once

开发者 https://www.devze.com 2022-12-21 04:59 出处:网络
What would cause this? I have a grouped tableView that I\'ve added in IB.2 groups.3 rows in each group.

What would cause this?

I have a grouped tableView that I've added in IB. 2 groups. 3 rows in each group.

It displays fine when my app is first run. (So I know I'm doing SOMETHING right. Wouldn't that mean that I (at least) have my Delegate, DataSource, IBOutlets, and connections set up correctly?)

But when I click on a button that calls [myTable reloadData] it just crashes.

Initially, I thought it was due to my changes in the number of groups, number of rows, or changing the data in my dataSource (just a small NSMutableArray).

But the sam开发者_JAVA百科e thing happens when I change NO data: Works fine the first time my tableView is displayed. But crashes when I call [myTable reloadData]. (Whether the data has changed or not.)

I've stripped my code down to a barebones minimum... trying to find this bug.


-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIndentifer = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifer];

    if(cell == nil)
       cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIndentifer] autorelease];

    cell.textLabel.text = @"Left Test"; 
    cell.detailTextLabel.text = @"Right Test";

    return cell;
}

Here's the button-click code:

-(IBAction) reloadTable:(id)sender
{
    if(myTable == nil)
        NSLog(@"myTable is nil");
    else
        [myTable reloadData];
}

Here's the "error" (no help at all):

[Session started at 2010-02-19 10:04:14 -0100.]
GNU gdb 6.3.50-20050815 (Apple version gdb-967) (Tue Jul 14 02:11:58 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 1081.
kill
kill
quit

The Debugger has exited with status 0.(gdb) 

I've even tried hard-coding the "number of groups", "number of rows", "header text", "foot text", and "cell text". (In case my math was wrong calculating my objectAtIndex... or I had an array-dataSource that didn't have enough elements.)

Always the same problem: Displays fine the first time. Crashes when I try to reloadData.


Well, if myTable is nil, but the tableview is on the screen, then it's a pretty good indicator that you don't have your IBOutlet properly hooked up. I'll bet if you NSLog(@"%@", myTable); in viewDidLoad (after calling super's, of course), you'll see (null) logged to the console.

When the UITableViewController first loads, the tableview (accessible via [self tableView]) will reloadData, which is why it works once, but won't reload again (because your outlet isn't hooked up).

I'd just ditch the outlet entirely (unless you're not using a UITableViewController) and use [self tableView].

0

精彩评论

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

关注公众号