我正在使用核心数据而且我是obj-c的新手。我正在尝试将核心数据中的“纬度”和“经度”传递给mapViewController
。
代码:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"ShowMap"]) {
HaritaVC *destViewController = segue.destinationViewController;
NSIndexPath *path = [self.myTableView indexPathForSelectedRow];
NSString *lattoPass = [NSString stringWithString:[[self.fetchedRecordsArray objectAtIndex:path.row]objectForKey:@"lat"]];
NSString *lontoPass = [NSString stringWithString:[[self.fetchedRecordsArray objectAtIndex:path.row]objectForKey:@"lon"]];
destViewController.latt = [[NSString alloc] initWithFormat:@"%@",lattoPass];
destViewController.lonn = [[NSString alloc] initWithFormat:@"%@",lontoPass];
}
}
和我的“tableview”代码:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"MainCell";
CellDetail *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Notlar * notlar = [self.fetchedRecordsArray objectAtIndex:indexPath.row];
cell.titleLabel.text = [NSString stringWithFormat:@"%@ %@, %@ ",notlar.bilgi,notlar.notlar,notlar.tarih];
return cell;
}
当我点击tableViewCell
时,我收到此错误:
'NSInvalidArgumentException', reason: '-[Notlar objectForKey:]: unrecognized selector sent to instance 0x1aa56b60'
答案 0 :(得分:0)
你在Notlar类型的对象中调用objectForKey,它似乎没有实现这个方法,在这里:
NSString *lattoPass = [NSString stringWithString:[[self.fetchedRecordsArray objectAtIndex:path.row]objectForKey:@"lat"]];
NSString *lontoPass = [NSString stringWithString:[[self.fetchedRecordsArray objectAtIndex:path.row]objectForKey:@"lon"]];
你的fetchedRecordsArray包含Notlar对象,而不是词典,这就是你无法调用此方法的原因。
如果没有更多信息,我无法告诉你如何完全解决它,但有两种可能性:你的Notlar对象包含一个lat和一个lon属性,你只需要:
NSString *lattoPass = [NSString stringWithString:[(Notlar *)[self.fetchedRecordsArray objectAtIndex:path.row] lat];
NSString *lontoPass = [NSString stringWithString:[(Notlar *)[self.fetchedRecordsArray objectAtIndex:path.row] lon];
或者您应该访问其他地方使用lon和lat值而不是fetchedRecordsArray的字典数组。