我有一個帶數據的NSMutable數組。cellForRowAtIndexPath崩潰
我想在方法「cellForRowAtIndexPath」填充單獨的行。
表視圖不斷崩潰,我不知道爲什麼。
問題出在這一行「cell.ergebnissLabel.text = [result objectAtIndex:indexPath.row]」。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
static NSString *CellIdentifier = @"ErgebnisseCell";
ErgebnisseCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (indexPath.section == 0) {
NSDictionary*filtertNew = [self.nummeriertesArray objectAtIndex:0];
NSArray *result = [[filtertNew allKeys] objectAtIndex:1]
cell.ergebnissLabel.text = [result objectAtIndex:indexPath.row];
}
return cell;
}
錯誤消息是這樣的。
2014-02-28 17:32:11.208 Info[2451:70b] -[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x10950c110
2014-02-28 17:32:11.210 Info[2451:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x10950c110'
*** First throw call stack:
(
0 CoreFoundation 0x0000000101caf295 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000101a0d99e objc_exception_throw + 43
2 CoreFoundation 0x0000000101d4045d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000101ca0b8d ___forwarding___ + 973
4 CoreFoundation 0x0000000101ca0738 _CF_forwarding_prep_0 + 120
5 Info 0x000000010001f0da -[ErgebnisseTableViewController tableView:cellForRowAtIndexPath:] + 394
6 UIKit 0x000000010069574a -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 348
7 UIKit 0x000000010067bb1b -[UITableView _updateVisibleCellsNow:] + 2337
8 UIKit 0x000000010068cfc1 -[UITableView layoutSubviews] + 207
9 UIKit 0x0000000100621943 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 354
10 QuartzCore 0x000000010021cdf2 -[CALayer layoutSublayers] + 151
11 QuartzCore 0x0000000100211959 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363
12 QuartzCore 0x00000001002117da _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
13 QuartzCore 0x00000001001856e4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 252
14 QuartzCore 0x000000010018675c _ZN2CA11Transaction6commitEv + 394
15 UIKit 0x00000001005c01f1 _UIApplicationHandleEventQueue + 10863
16 CoreFoundation 0x0000000101c3eb21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
17 CoreFoundation 0x0000000101c3e3f2 __CFRunLoopDoSources0 + 242
18 CoreFoundation 0x0000000101c5a26f __CFRunLoopRun + 767
19 CoreFoundation 0x0000000101c59b83 CFRunLoopRunSpecific + 467
20 GraphicsServices 0x0000000103587df5 GSEventRunModal + 161
21 UIKit 0x00000001005c2003 UIApplicationMain + 1010
22 Info 0x0000000100036143 main + 115
23 libdyld.dylib 0x00000001025a35fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
謝謝。
NSString不會「識別」objectAtIndex。很可能是因爲你的變量'result'包含一個NSString,而不是NSArray。 –