NSDictionaries的NSDictionary

jrb*_*819 1 arrays xcode objective-c nsdictionary ios

我在使用以下代码创建NSDictionaries的NSDictionary时遇到问题.没有编译错误,但在运行时,它在此代码上失败.

NSDictionary *section0 = [NSDictionary dictionaryWithObjectsAndKeys:
                            [NSDictionary dictionaryWithObjectsAndKeys:
                                @"Caller ID", @"label",
                                @"name", @"field",
                                @"Call", @"fieldType", nil
                            ], 0,
                            [NSDictionary dictionaryWithObjectsAndKeys:
                                @"Number", @"label",
                                @"number", @"field",
                                @"Call", @"fieldType", nil
                            ], 1,
                            nil
                         ];
Run Code Online (Sandbox Code Playgroud)

这是我的第一个应用程序,因此非常感谢您提供的任何帮助.

Cra*_*tis 9

你的钥匙也必须是物体.(除了值之外.)您使用01int类型作为键.您应该使用以下内容:

[NSNumber numberWithInt:0];
Run Code Online (Sandbox Code Playgroud)

因此,您的字典代码如下所示:

NSDictionary *section0 = [NSDictionary dictionaryWithObjectsAndKeys:
                            [NSDictionary dictionaryWithObjectsAndKeys:
                                @"Caller ID", @"label",
                                @"name", @"field",
                                @"Call", @"fieldType", nil
                            ], [NSNumber numberWithInt:0],
                            [NSDictionary dictionaryWithObjectsAndKeys:
                                @"Number", @"label",
                                @"number", @"field",
                                @"Call", @"fieldType", nil
                            ], [NSNumber numberWithInt:1],
                            nil
                         ];
Run Code Online (Sandbox Code Playgroud)