2011-01-25 148 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]];