Objective c 我能';t将数据uitableviewcell传递给destinationviewcontroller

Objective c 我能';t将数据uitableviewcell传递给destinationviewcontroller,objective-c,uitableview,segue,Objective C,Uitableview,Segue,我使用的是核心数据,我是obj-c的新手。我正在尝试将核心数据中的“纬度”和“经度”传递到mapViewController 代码: - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"ShowMap"]) { HaritaVC *destViewController = segue.destinationViewCo

我使用的是核心数据,我是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”代码:

当我单击
tableViewCell
时,出现以下错误:


'NSInvalidArgumentException',原因:'-[Notlar objectForKey::]:无法识别的选择器发送到实例0x1aa56b60'

您正在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。

显示您的
didSelectRowAtIndexpath
看起来fetchedRecordArray返回的值不是Notlar对象的实例。逐步浏览代码,也许打印出返回的对象,以了解它是什么。可能是零值吧?不客气。如果它对你有用,你应该考虑接受我的答案是正确的(在答案投票计数下的复选标记)。
NSString *lattoPass = [NSString stringWithString:[(Notlar *)[self.fetchedRecordsArray objectAtIndex:path.row] lat];
NSString *lontoPass = [NSString stringWithString:[(Notlar *)[self.fetchedRecordsArray objectAtIndex:path.row] lon];