Objective c XCode NSDictionary错误-objectForKey::发送到实例的选择器无法识别
我的XCode(IOS)中有一个表视图,它将数据传递给我的第二个表视图 FirstTableViewController.mObjective c XCode NSDictionary错误-objectForKey::发送到实例的选择器无法识别,objective-c,xcode,web-services,uitableview,Objective C,Xcode,Web Services,Uitableview,我的XCode(IOS)中有一个表视图,它将数据传递给我的第二个表视图 FirstTableViewController.m - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if([segue.identifier isEqualToString:@"ShowSecond"]){ NSIndexPath *indexPath = [self.tableView indexPathFor
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"ShowSecond"]){
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
SecondViewController *List = segue.destinationViewController;
List.cat = [myObjectCat objectAtIndex:indexPath.row];
}
}
SecondTableViewController.h:这就是我所拥有的
@property (nonatomic,weak) NSDictionary *cat;
SecondTableViewController.m
for (NSDictionary *clickresult in cat) {
NSString *title_cat = [clickresult objectForKey:@"name"];
NSLog(@"%@", title_cat);
}
在运行代码时,我遇到以下错误:
WebService[7153:90b]0 WebService[7153:90b]-[\uu NSCFConstantString
objectForKey::发送到实例0x9ae0的选择器无法识别
WebService[7153:90b]***由于未捕获异常而终止应用程序
“NSInvalidArgumentException”,原因:'-[\uu NSCFConstantString
objectForKey::无法识别的选择器已发送到实例0x9ae0'
这是我在运行代码时在调试器左侧看到的内容
cat = (_NSDictionaryl *) class name = _NSDictionaryl
-> [0] = @"name" : @"This is my first title"
-> [1] = @"icon" : @"icon.png"
我需要做什么才能将元素的名称和图标值传递给第二个表视图控制器(cat)
任何帮助都将不胜感激
谢谢好的。有你的问题。您正在使用弱属性
@property (nonatomic,weak) NSDictionary *cat;
对于您的变量cat
。它将在初始化后立即释放。尝试对其使用strong
@property (nonatomic,strong) NSDictionary *cat;
希望这能解决问题这就是我解决问题的方式
NSString *myTitle = [cat objectForKey:@"name"];
NSString *myIcon = [cat objectForKey:@"icon"];
如果不知道什么是
cat
,就无法具体说明失败的原因。(请注意,调试器显示不可靠--您必须在控制台中使用NSLog或dopo cat
。@hostedvn如果答案解决了您的问题,请接受我这是重复的吗?你们这些家伙更担心这个,而不是试图帮助回答问题。悲伤:S