我正試圖按照教程,並在我自己的代碼中實現它。Objective-C與字典和數組拋出NSInvalidArgumentException
這裏是我得到的問題 -
數據,心願和wishlistids都是NSMutableArrays。我知道這個問題發生在我嘗試將字典添加到數據數組的行中。看代碼:
- (void)setupWishlists:(NSString *)informationReturned
{
if(![informationReturned isEqualToString:@""]){
//[data setArray:[informationReturned componentsSeparatedByString:@"."]]; //this works too, its an old method I kept just incase... this one has the raw combined wishlists name and id together. Here I attempt to split them.
NSMutableArray *temporaryArray = [NSMutableArray array];
NSArray *rawArray = [informationReturned componentsSeparatedByString:@"."];
for (NSString *item in rawArray) {
//so pretty much here we have the raw information that came back... remove the IDs
[temporaryArray setArray:[item componentsSeparatedByString:@","]];
[wishlists addObject:[temporaryArray objectAtIndex:0]];
[wishlistids addObject:[temporaryArray objectAtIndex:1]];
}
//Initialize the array.
NSDictionary *myWishlistsDict = [NSDictionary dictionaryWithObject:[NSArray arrayWithArray:wishlists] forKey:@"My Wishlists"];
[data addObject:myWishlistsDict]; //GETTING PROBLEM HERE!!! IF I COMMENT THIS LINE IT IS FINE
}
NSLog(@"Raw Wishlists Array: %@", [data description]);
}
而且我肯定的Alloc所有這些陣列等的功能,我相信這個人之前先運行。
data = [[NSMutableArray alloc] init];
wishlists = [[NSMutableArray alloc] init];
wishlistids = [[NSMutableArray alloc] init];
這是錯誤(在控制檯看到:
2010-08-26 19:53:47.598 LoginApp[7604:207] -[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x59b5760
2010-08-26 19:53:47.600 LoginApp[7604:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x59b5760'
反正我覺得我漏掉了什麼......如果我沒請告訴我,我一定會很快回答
這就是我正在做的。從數組中取出一個對象並假定它是一個字符串:D謝謝! – 2010-08-27 20:27:14