【发布时间】:2012-03-06 17:41:54
【问题描述】:
将 TableView 的数据源从带有对象(我找到的示例)的 NSArray 更改为带有填充表格视图所需的实际值的 NSMutableArray 时出现错误。
错误:
纬度是:33, 长是:-74, 2012-03-06 12:27:58.380 x[606:fb03]-[__NSCFNumber isEqualToString:]:无法识别的选择器发送到实例 0x6b64280 2012-03-06 12:27:58.381 x[606:fb03] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFNumber isEqualToString:]:无法识别的选择器发送到实例 0x6b64280 '
我设置 self.measurement 和 self.subinfo 的原始方式被注释掉了。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MeasurementCell"];
switch (indexPath.section)
{
case kMeasurement:
cell.textLabel.text=[self.measurements objectAtIndex:indexPath.row];
cell.detailTextLabel.text=[self.subinfo objectAtIndex:indexPath.row];
break;
default:
cell.textLabel.text=@"Unkown";
}
return cell;
}
- (void)viewDidLoad
{
appdelegate = [[AppDelegate alloc]init];
//get lat
NSArray* fmArray = [appdelegate fetchEvents:@"Field_Measurement"];
NSMutableArray* latBindArray = [[NSMutableArray alloc]init];
NSMutableArray* longBindArray = [[NSMutableArray alloc]init];
for (Field_Measurement *fm in fmArray)
{
[latBindArray addObject:fm.latitude];
NSLog(@"lat is: %@", fm.latitude);
}
for (Field_Measurement *fm in fmArray)
{
[longBindArray addObject:fm.longitude];
NSLog(@"long is: %@", fm.longitude);
}
self.measurements = latBindArray;//[[NSArray alloc]initWithObjects:@"03/05/2012 @ 15:12", @"03/05/2012 @ 11:11", nil];
self.subinfo = latBindArray;//[[NSArray alloc]initWithObjects:@"Beta: 0.0234",@"Alpha: 3.977", nil];
[super viewDidLoad];
}
这是我第一次尝试使用表视图(并且是 Objective-c 的新手),因此任何关于如何从 NSMutableArray 填充表视图的想法都会有所帮助。我有一个 sqlite 数据库,如果有帮助,我会从中提取这些记录。
谢谢
【问题讨论】:
标签: iphone ios xcode sqlite uitableview