2010-01-13 25 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]; 

你能在這一行設置一個斷點並轉儲「名單」?