2011-01-25 192 views
0

UITableView在滾動時崩潰。下面是示例代碼..UITableView在滾動時崩潰

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

NSLog(@"Total Count: %d",count); 
return [ObjectArray count] ; 
} 


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

static NSString *CellIdentifier = @"Cell"; 


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 




    if (cell == nil) { 

    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 

    cell.textLabel.numberOfLines = 0; 
    cell.textLabel.font = [UIFont fontWithName:@"Arial" size:12.0]; 
    cell.detailTextLabel.font = [UIFont fontWithName:@"Arial" size:10.0]; 

    [cell.textLabel sizeToFit]; 
    [cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton]; 


    } 

// Configure the cell. 

NSLog(@"Row Number %d", indexPath.row); 
cell.textLabel.text = [ObjectArray name]; 
return cell; 
} 

在控制檯中,我可以看到總計數= 22

Row Number 0 
Row NUmber 1 
. 
. 
Row Number 21 (This row number will pull the last object from ObjectArray) 

現在,如果我嘗試滾動它崩潰了......爲什麼?誰能幫我這個...

+1

請正確重新格式化您的代碼併發布崩潰的堆棧跟蹤。 – 2011-01-25 22:25:25

+0

你還可以提到更多關於ObjectArray的信息。目前ObjectArray正在被使用,就像它不是一個數組。即。 [ObjectArray name] ...不從數組中拉出任何對象 – martinws 2011-01-25 22:31:58

回答

0

我真的不明白這行代碼

  cell.textLabel.text = [ObjectArray name]; 

如果ObjectArray是NSArray的實例,那麼它不會給選擇作出迴應。無論如何,你可能想返回水果像

  cell.textLabel.text = [ObjectArray objectAtIndex: [indexPath row]];