我对在iOS中进行开发非常陌生。我试图通过表视图中的segue传递一些数据。这就是我要传递的数据:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:@"ShowContactDetails"]) {
    ContactDetailsViewController *dvc = [segue destinationViewController];
    NSIndexPath *path = [self.tableView indexPathForSelectedRow];
    Contact *c = [jsonResults objectAtIndex:path.row];
    [dvc setSelectedContact:c];
    }
}


一切顺利,当我在NSLog上执行selectedContact时,这就是我得到的:

2012-05-21 15:15:42.410 Test[8352:f803] {
category = Prospect;
id = 19895;
label = "John  Doe";
}


问题是,我不知道如何单独访问这些项目。我尝试调用objectForKey之类的东西,但出现错误。

最佳答案

从您的NSLog的输出中,selectedContact似乎是一个NSDictionary对象。尝试使用[selectedContact valueForKey]而不是[selectedContact objectForKey]。

例如:

NSLog(@"Name: %@", [selectedContact valueForKey:@"label"]);

关于ios - 从对象检索数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10692083/

10-11 16:14