【发布时间】:2010-08-27 03:39:46
【问题描述】:
我正在尝试按照教程并在我自己的代码中实现它。
这是我遇到的问题 -
data、wishlists 和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]);
}
此外,我肯定会将所有这些数组等分配到一个我肯定会在此之前运行的函数中。
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'
无论如何,我觉得我遗漏了一些东西...如果我遗漏了,请告诉我,我一定会尽快回复。
【问题讨论】:
标签: objective-c arrays dictionary