我正在使用此代码,它正在提供异常
NSMutableArray *streams = (NSMutableArray *)[feed valueForKey:@"comments"];
NSMutableArray *streams1 = (NSMutableArray *)[streams valueForKey:@"data"];
//NSMutableArray *streams2 = (NSMutableArray *)[streams1 valueForKey:@"message"];
// loop over all the stream objects and print their titles
int index;
NSMutableDictionary *stream;
for (index = 0; index < [feed count];index++) {
stream = (NSMutableDictionary *)[streams1 objectAtIndex:index];
NSLog(@"Name of sender is: %@", [stream valueForKey:@"message"]);
}
FaceBookTable *detailViewController = [[FaceBookTable alloc] initWithNibName:@"FaceBookTable" bundle:nil];
// ...
// Pass the selected object to the new view controller.
detailViewController.fbGraph = fbGraph;
detailViewController.dummyArray = [ feed valueForKey:@"message"];
detailViewController.dict = stream;
}
例外是
-[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x5dae960
2011-06-15 16:14:07.835 MultiSocial[8042:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x5dae960'
而我的其他代码工作正常
NSMutableArray *streams = (NSMutableArray *)[feed valueForKey:@"from"];
lueForKey:@"message"];
// loop over all the stream objects and print their titles
int index;
NSMutableDictionary *stream;
for (index = 0; index < [feed count];index++) {
stream = (NSMutableDictionary *)[streams objectAtIndex:index];
NSLog(@"Name of sender is: %@", [stream valueForKey:@"message"]);
}
请帮忙
这里是崩溃日志
2011-06-15 17:05:42.148 MultiSocial[8583:207] -[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x5d05f50
2011-06-15 17:05:42.156 MultiSocial[8583:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0x5d05f50'
*** Call stack at first throw:
(
0 CoreFoundation 0x013cabe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0151f5c2 objc_exception_throw + 47
2 CoreFoundation 0x013cc6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x0133c366 ___forwarding___ + 966
4 CoreFoundation 0x0133bf22 _CF_forwarding_prep_0 + 50
5 UIKit 0x00649405 -[UITableViewLabel setText:] + 84
6 MultiSocial 0x00046147 -[FaceBookTable tableView:cellForRowAtIndexPath:] + 467
7 UIKit 0x0045f7fa -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
8 UIKit 0x0045577f -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
9 UIKit 0x0046a450 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
10 UIKit 0x00462538 -[UITableView layoutSubviews] + 242
11 QuartzCore 0x01e98451 -[CALayer layoutSublayers] + 181
12 QuartzCore 0x01e9817c CALayerLayoutIfNeeded + 220
13 QuartzCore 0x01e9137c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
14 QuartzCore 0x01e910d0 _ZN2CA11Transaction6commitEv + 292
15 QuartzCore 0x01ec17d5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
16 CoreFoundation 0x013abfbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
17 CoreFoundation 0x013410e7 __CFRunLoopDoObservers + 295
18 CoreFoundation 0x01309bd7 __CFRunLoopRun + 1575
19 CoreFoundation 0x01309240 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x01309161 CFRunLoopRunInMode + 97
21 GraphicsServices 0x0190f268 GSEventRunModal + 217
22 GraphicsServices 0x0190f32d GSEventRun + 115
23 UIKit 0x003fa42e UIApplicationMain + 1160
24 MultiSocial 0x00002740 main + 102
25 MultiSocial 0x000026d1 start + 53
)
答案 0 :(得分:0)
根据崩溃日志 - [__ NSArrayI isEqualToString:],您的代码中存在一些错误。在崩溃报告中可以清楚地看到,isEqualToString方法适用于NSString对象,但在您的代码中,它是在NSArray上调用的。
只需调试您的应用,您就会找到解决方案。
<强>更新强>
//Make sure that feed return an array for the key comments
NSArray *streams = (NSArray *)[feed valueForKey:@"comments"];
NSArray *streams1 = (NSArray *)[streams valueForKey:@"data"];
NSLog(@"comments : %@",streams);
//When you are running loop only last index value will be copied into your dictionary named stream so remove the loop.
FaceBookTable *detailViewController = [[FaceBookTable alloc] initWithNibName:@"FaceBookTable" bundle:nil];
// ...
// Pass the selected object to the new view controller.
detailViewController.fbGraph = fbGraph;
detailViewController.dummyArray = [ feed valueForKey:@"message"];
detailViewController.dict = streams;
}
//你的tableView cellForRowAtIndexPath方法应如下所示
//First get the dictionary
if(dict){
NSDictionary *stream = (NSDictionary *)[dict objectAtIndex:indexPath.row];
if(stream){
NSDictionary * messages = (NSDictionary *[stream valueForKey:@"Message"];
NSString *comment = [messages valueForKey:@"comment"];
cell.textLabel.text = comment;
}
}
答案 1 :(得分:0)
你一直在为NSArray分配NSString对象。所以用断点进行调试
答案 2 :(得分:0)
NSMutableArray *arr = [[[feed valueForKey:@"comments"]valueForKey:@"data" ]valueForKey:@"id"];
for (NSString* cid in [arr objectAtIndex:0]) {
NSLog(@"cid is : %@ \n\n",cid);
}