Iphone UITableView在滚动时崩溃

Iphone UITableView在滚动时崩溃,iphone,uitableview,Iphone,Uitableview,UITableView在滚动时崩溃。下面是示例代码 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSLog(@"Total Count: %d",count); return [ObjectArray count] ; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForR

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)

现在如果我试图滚动它崩溃了…为什么?有人能帮我吗…

我不太懂这行代码

         cell.textLabel.text = [ObjectArray name];
如果ObjectArray是NSArray实例,则它不会响应该选择器。不管怎样,你可能想要像这样返回smth

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

请正确地重新格式化您的代码,并发布崩溃的堆栈跟踪。您还可以提到有关ObjectArray的更多信息吗。目前,ObjectArray的使用就像它不是数组一样。ie.[ObjectArray名称]。。。如果不从“数组”中提取任何对象,您可能应该确保数据源被保留。通常情况下,scroll上的崩溃是由于尝试访问空/零数据源造成的。我的错..我试图修改实际代码,结果让您感到困惑。ObjectArray是一个NSMutableArray。我确信ObjectArray正在填充对象类型“MyObject”。MyObject具有名为“name”和“age”的实例变量。下面是修改后的NSLog@Row编号%d,indexath.row;cell.textlab.text=[ObjectArray名称];MyObject*temp=[ObjectArray objectAtIndex:indexath.row]cell.textLabel.text=[temp name];[临时发布]我的开发机器正在工作。在记事本上写下这个。请忽略任何语法错误。[temp release]-您正在释放它,因此当您的表视图第二次尝试访问该项时,它已经被释放。删除该行原因是此处保留了temp.name变量,而不是tempitself@Max那我怎么能打印所有的对象呢。。??你能帮我修改一下代码吗?好吧,我已经告诉过你:当你第一次访问数组中的项时,它是可以的。但是你要释放它,所以当我们第二次尝试访问它时,链接是无效的。只需拆下[temp release]线路即可