gpt4 book ai didi

ios - 从对象中检索数据

转载 作者:行者123 更新时间:2023-11-28 22:56:31 25 4
gpt4 key购买 nike

我对 iOS 开发还很陌生。我正在尝试通过 TableView 中的 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];
}
}

它顺利通过,当我在 selectedContact 上执行 NSLog 时,这就是我得到的:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com