cellForRowAtIndexPath 在第一次后没有调用并给出错误 [__NSArrayI length]: unrecognized selector sent to instance

Posted

技术标签:

【中文标题】cellForRowAtIndexPath 在第一次后没有调用并给出错误 [__NSArrayI length]: unrecognized selector sent to instance【英文标题】:cellForRowAtIndexPath does not called after first time and gives error [__NSArrayI length]: unrecognized selector sent to instance 【发布时间】:2015-09-05 11:41:50 【问题描述】:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
  return dict.count;


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

  static NSString *simpleTableIdentifier = @"RestaurantResultsCell";
  RestaurantDetailsViewCell *cell = (RestaurantDetailsViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
  if (cell == nil) 
      NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"restaurantDetailsCell" owner:self options:nil];
      cell = [nib objectAtIndex:0];
  

  arrResponse =[NSArray arrayWithObject:dict];
  arr = [arrResponse objectAtIndex:0];

  dictio = [arr objectAtIndex:0];

  cell.cusineRestLabel.text = [[dictio valueForKey:@"restaurant_name"]objectAtIndex:indexPath.row];

  NSLog(@"cell is %@",cell.cusineRestLabel.text);

  //    cell.cusineRestLabel.text = [dic objectForKey:@"restaurant_name"];

  cell.cusineRestAddress.text = [dictio valueForKey:@"restaurant_streetaddress"];

  NSLog(@"cell is %@",cell.cusineRestAddress.text);

  cell.cusineDeliveryTime.text = [dictio valueForKey:@"restaurant_delivery"];

  NSLog(@"cell is %@",cell.cusineDeliveryTime.text);

  return cell;

第一次执行后[__NSArrayI 长度]:无法识别的选择器发送到实例

【问题讨论】:

真的吗?你的问题在哪里?编辑您的问题并以适当的方式提问。 重新格式化代码,提出问题,提供有用的错误解释(在哪一行),努力! 返回单元格后,控件进入封闭括号,然后它应该上升并重新执行所有行但崩溃 哈哈哈,什么?你读过我们的 cmets 吗? 不要使用字典作为数据源。由于字典是无序的,因此您将按随机顺序获取项目。 【参考方案1】:

这段代码

  arrResponse =[NSArray arrayWithObject:dict];
  arr = [arrResponse objectAtIndex:0];

是一种很奇怪的写法

  arr = (id)dict;

这看起来不像是一个错误,而是故意混淆。那么它是什么:数组还是字典?

【讨论】:

以上是关于cellForRowAtIndexPath 在第一次后没有调用并给出错误 [__NSArrayI length]: unrecognized selector sent to instance的主要内容,如果未能解决你的问题,请参考以下文章

多次加载时 cellForRowAtIndexPath 行为异常

tableview:cellForRowAtIndexPath 没有被调用

Objective C - cellForRowAtIndexPath 单元格从不为零?

始终在第一个 Cell UICollectionView 中保存数据

tableView(cellForRowAtIndexPath) 与 tableView.cellForRowAtIndexPath()?

JS leetcode 猜数字 题解分析,我以为题目在第八层我在第一层,其实我在第三层题目在第一层