2010-01-13 75 views
0

当我滚动UITableView通过第一个单元格或最后一个单元格时,我的应用程序崩溃! 这是为什么发生?我用addObject添加:命名UItableview的对象。这是我在cellForRowAtIndexPath使用的代码。请帮助!我一直在想弄清楚什么是错误的时间!应用程序崩溃在cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString * DisclosureButtonCellIdentifier = 
    @"DisclosureButtonCellIdentifier"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: 
          DisclosureButtonCellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
             reuseIdentifier: DisclosureButtonCellIdentifier] 
       autorelease]; 
    } 
    NSUInteger row = [indexPath row]; 

NSString *rowString =nil; 

    rowString = [list objectAtIndex:row]; 

cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 
    [rowString release]; 
    return cell; 
+0

请在代码周围使用

块。 –
                        
                            
                                2010-01-13 16:05:09
                            
                        
                    

+0

请将代码分配给列表数组,并发布以下方法 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)部分 – FelixLam 2010-01-13 16:06:34

回答

3

你打电话给[rowString release];,但你永远不会保留它。

+0

有关该版本的+1;不仅你永远不会保留它,如果rowString不是零,你可能会释​​放一个自动释放的对象,这是一个非常糟糕的主意。 – 2010-01-13 16:27:00

+0

非常感谢!这是问题!上帝祝福你! – stefanosn 2010-01-13 16:35:47

0

是它抛出一个异常 - 我的猜测是该指数未设置:

rowString = [list objectAtIndex:row]; 

你能在这一行设置一个断点并转储“名单”?