简体   繁体   English

UITableView在滚动时崩溃

[英]UITableView crashes on scrolling

UITableView is crashing on scrolling . UITableView在滚动时崩溃。 Here is the sample code.. 这是示例代码。

- (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;
}

In console I can see Total count = 22. 在控制台中,我可以看到总数= 22。

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

Now if I try to scroll it crashes...why? 现在,如果我尝试滚动,它会崩溃...为什么? Can anyone help me with this ... 谁能帮我这个 ...

I don't really understand this line of code 我不太明白这行代码

         cell.textLabel.text = [ObjectArray name];

If ObjectArray is a NSArray instance, then it would not respond to that selector. 如果ObjectArray是NSArray实例,则它将不会响应该选择器。 And anyway you probably want to return smth like 无论如何,您可能想返回

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM