分组UITableView显示正常,但只显示一次

时间:2010-02-20 14:41:25

标签: iphone uitableview

导致这种情况的原因是什么?

我有一个我在IB中添加的分组tableView。 2组。每组3行。

首次运行我的应用时显示正常。 (所以我知道我正在做正确的事。这是不是意味着我(至少)我的Delegate,DataSource,IBOutlets和连接设置正确?)

但是当我点击一个调用[myTable reloadData]的按钮时,它就会崩溃。

最初,我认为这是由于我的组数,行数或更改dataSource中的数据的变化(只是一个小的NSMutableArray)。

但是当我更改NO数据时会发生同样的事情:第一次显示tableView时工作正常。但是当我拨打[myTable reloadData]时会崩溃。 (数据是否已更改。)

我已经将我的代码剥离到最低限度的准系统...试图找到这个错误。


-(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;
}

这是按钮点击代码:

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

这是“错误”(根本没有帮助):

[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) 

我甚至尝试过硬编码“组数”,“行数”,“标题文本”,“脚文本”和“单元格文本”。 (如果我的数学计算我的objectAtIndex错误...或者我有一个没有足够元素的array-dataSource。)

始终存在同样的问题:第一次显示正常。我尝试重新加载数据时崩溃。

1 个答案:

答案 0 :(得分:0)

好吧,如果myTable为零,但桌面视图在屏幕上,那么这是一个非常好的指标,表明您没有正确连接IBOutlet。我敢打赌,如果NSLog(@"%@", myTable); viewDidLoad(当然,在调用super之后),你会看到(null)已登录到控制台。

首次加载UITableViewController时,tableview(可通过[self tableView]访问)将reloadData,这就是为什么它可以运行一次,但不会重新加载(因为你的插座没有连接)

我只是完全放弃了出口(除非你没有使用UITableViewController)并使用[self tableView]