2014-06-11 2 views
0
int x = 5; 
int t = 6; 
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:@"books.book", @"og:type", 
         @"www.goodreads.com", @"og:url", 
         @"Snow Crash", @"og:title", 
         @"978-3-16-148410-0",@"books:isbn", 
         @"http://en.wikipedia.org/wiki/File:Snowcrash.jpg", @"og:image", 
         @"www.google.com",@"og:audio:url", 
         @"www.facebook.com",@"al:windows_universal:url", 
         @"www.facebook.com",@"al:windows_phone:url", 
         @"www.facebook.com",@"al:windows:url", 
         @"www.facebook.com",@"al:iphone:url", 
         @"www.facebook.com",@"al:ipad:url", 
         x,@"books:rating:value", 
         t,@"books:rating:scale", 
         @"In reality, Hiro Protagonist delivers pizza for Uncle Enzo’s CosoNostra Pizza Inc., but in the Metaverse he’s a warrior prince. Plunging headlong into the enigma of a new computer virus that’s striking down hackers everywhere, he races along the neon-lit streets on a search-and-destroy mission for the shadowy virtual villain threatening to bring about infocalypse. Snow Crash is a mind-altering romp through a future America so bizarre, so outrageous…you’ll recognize it immediately.", @"og:description", 
         @"Chan Yee Choong", @"books:author", 
         @"Science Fiction",@"books:genre", 
         @"eu_es",@"books:language:locale", 
         @[@"en_us",@"ca_es",@"cs_cz"],@"books:language:alternate",nil]; 

나는 사전을 만들려고 해요 위에 당신이 볼 수 있듯이, 그러나 나는이 같은 오류가 발생합니다.'NSInvalidArgumentException', 이유 : '+ [NSDictionary와의 dictionaryWithObjectsAndKeys :] : 내가 코드를 실행할 때마다

2014-06-11 23:50:50.338 TestApp[8374:60b] *** Terminating app due to uncaught exception  'NSInvalidArgumentException', reason: '+[NSDictionary dictionaryWithObjectsAndKeys:]: second object of each pair must be non-nil. Or, did you forget to nil-terminate your parameter list?' 
*** First throw call stack: 
(
0 CoreFoundation      0x00000001019ef495 __exceptionPreprocess + 165 
1 libobjc.A.dylib      0x000000010174e99e objc_exception_throw + 43 
2 CoreFoundation      0x00000001019d27e3 +[NSDictionary dictionaryWithObjectsAndKeys:] + 1043 
3 TestApp        0x000000010000724d -[CYCViewController postBooks:] + 1021 
4 UIKit        0x00000001002fcf06 -[UIApplication sendAction:to:from:forEvent:] + 80 
5 UIKit        0x00000001002fceb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17 
6 UIKit        0x00000001003d9880 -[UIControl _sendActionsForEvents:withEvent:] + 203 
7 UIKit        0x00000001003d8dc0 -[UIControl touchesEnded:withEvent:] + 530 
8 UIKit        0x0000000100333d05 -[UIWindow _sendTouchesForEvent:] + 701 
9 UIKit        0x00000001003346e4 -[UIWindow sendEvent:] + 925 
10 UIKit        0x000000010030c29a -[UIApplication sendEvent:] + 211 
11 UIKit        0x00000001002f9aed _UIApplicationHandleEventQueue + 9579 
12 CoreFoundation      0x000000010197ed21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
13 CoreFoundation      0x000000010197e5f2 __CFRunLoopDoSources0 + 242 
14 CoreFoundation      0x000000010199a46f __CFRunLoopRun + 767 
15 CoreFoundation      0x0000000101999d83 CFRunLoopRunSpecific + 467 
16 GraphicsServices     0x0000000103b66f04 GSEventRunModal + 161 
17 UIKit        0x00000001002fbe33 UIApplicationMain + 1010 
18 TestApp        0x0000000100008153 main + 115 
19 libdyld.dylib      0x00000001020875fd start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 

NIL 추가를 통한 해결책을 따라했지만 여전히 작동하지 않습니다. 모든 것이 잘 배치됩니다. 나는 점검하고 확인했다.

답변

1

귀하의 사전에 nil 일 수있는 값은 xt입니다. 위의 오류는 객체가 nil 일 수 없으며 사전에 키 객체 대신 nil을 넣을 수 없으므로 @""을 입력하거나 [NSNull null]을 입력 할 수도 있습니다.

업데이트

위의 값이 아닌 객체 값입니다

int x = 5; 
int t = 6; 

넣어하려고하는 것처럼, 사전 객체를 필요로 넣어보십시오.

[NSNumber numberWithInt:x] 
[NSNumber numberWithInt:t] 
+0

미안하지만 x와 t를 추가하는 것을 잊어 버렸습니다. NSDictionary 위의 코드는 없습니다. – user3526002

+0

@ user3526002 내 업데이트 참조 – iphonic

관련 문제