填充表視圖時出現奇怪的錯誤。這是我做過無數次的事情,但現在我很難理解那些可能非常簡單的事情。也許我剛睡了太久。錯誤cellForRowAtIndexPath
我有一個名爲riverGauge的對象,負責從Web服務下載數據。然後將相關數據放置到NSDictionary對象中並作爲屬性返回。從字典中的鍵構建的鍵的數組也作爲屬性返回。
在我的cellForRowAtIndexPath方法中,我使用鍵數組來查找字典中的值並將它們呈現在表視圖中。相當標準。這是我的cellForRowAtIndexPath:
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellID = @"DataCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
NSDate *key = [riverGauge.gaugeFlowKeys objectAtIndex:indexPath.row];
NSString *cellText = [riverGauge.gaugeFlows objectForKey:key];
NSLog(@"CELL TEXT = %@", cellText);
[cell.textLabel setText:cellText]; // Error on last pass. No errors without this line
return cell;
}
最後一個單元格填充我正在一個無法識別的選擇異常後。
2014-08-28 12:07:20.318 RiverGuage[9858:60b] -[__NSCFNumber length]: unrecognized selector sent to instance 0xa07b180
2014-08-28 12:07:20.319 RiverGuage[9858:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0xa07b180'
我已驗證返回的鍵數與字典中的記錄數匹配,並且指定的鍵有值。日誌語句適用於列表中的每個項目,並且不會返回任何不尋常的內容。如果註釋了[cell.textLabel setText:cellText],cellForRowAtIndexPath方法將無錯地返回。任何想法爲什麼發生這種情況?謝謝!
你最近一次通過的日誌('cellText')是什麼? – Larme 2014-08-28 16:25:37
您正在嘗試將NSNumber對象設置爲單元格文本 – Injectios 2014-08-28 16:26:36
這是字典中的最後一項 - 正是我期望的 – Pheepster 2014-08-28 16:27:03