Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c Can';t将UIViewController子类添加到NSDictionary_Objective C_Ios_Nsmutabledictionary - Fatal编程技术网

Objective c Can';t将UIViewController子类添加到NSDictionary

Objective c Can';t将UIViewController子类添加到NSDictionary,objective-c,ios,nsmutabledictionary,Objective C,Ios,Nsmutabledictionary,我不想将UIViewController的子类添加到NSMutableDictionary中,因为UIViewController是一个NSObject,所以这应该没有问题 这是我的代码: NSArray *requestingPathes = [[NSArray alloc] initWithObjects:indexPath, nil]; requestingPair = [[NSMutableDictionary alloc] initWithObjectsAndKeys:requesti

我不想将UIViewController的子类添加到NSMutableDictionary中,因为UIViewController是一个NSObject,所以这应该没有问题

这是我的代码:

NSArray *requestingPathes = [[NSArray alloc] initWithObjects:indexPath, nil];
requestingPair = [[NSMutableDictionary alloc] initWithObjectsAndKeys:requestingPathes, dele, nil];
当委托“dele”(恰好是提到的子类)用于初始化字典“requestingPair”时,应用程序崩溃

错误是:

-[MainViewController copyWithZone:]: unrecognized selector sent to instance 0x7446b30
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MainViewController copyWithZone:]: unrecognized selector sent to instance 0x7446b30
0x7446b30是子类“MainViewController”的地址


为什么会发生这种情况?

-initWithObjects和keys:
需要一个对象和键的列表,按顺序交替使用object、key、object、key、nil。您所做的是尝试将您的
dele
对象作为键,从中可以检索值
RequestingPaths
;NSDictionary对象复制其键当您设置它们时,您的视图控制器不支持被复制,因此这是失败的。大概您想做的是这样的:

requestingPair = [[NSMutableDictionary alloc] initWithObjectsAndKeys:requestingPathes, @"paths", dele, @"delegate", nil];

然后,您可以通过调用
[requestingPair objectForKey:@“delegate”]
和带有
[requestPair objectForKey:@“paths”的路径来检索委托对象

-initWithObjects和keys:
需要一个对象和键的列表,按顺序交替使用object、key、object、key、nil。您要做的是尝试将您的
dele
对象作为键,从中可以检索值
请求路径
;NSDictionary对象在设置em,并且您的视图控制器不支持被复制,因此这是失败的。您可能想做的事情更像这样:

requestingPair = [[NSMutableDictionary alloc] initWithObjectsAndKeys:requestingPathes, @"paths", dele, @"delegate", nil];

然后,您可以通过调用
[requestingPair objectForKey:@“delegate”]
和带有
[requestPair objectForKey:@“paths”]
的路径来检索委托对象。您的字典密钥必须符合NSCopying协议,而UIViewController(和您的MainViewController)则不符合该协议


您希望dele是键还是值?它当前是键。

您的字典键必须符合NSCopying协议,而UIViewController(和您的MainViewController)不符合该协议


您希望dele是键还是值?它当前是键。

委托必须是他们键。有一个委托列表,每个委托都与indexPathes数组关联。我不知道该键被复制。因此我将委托地址存储为NSNumber。委托必须是他们键。有一个委托列表,每个委托都与indexPathes数组。我不知道密钥已被复制。因此我将代理的地址存储为NSNumber。