2012-04-07 58 views
0

我試圖創建一個向表格中加載一些推文的表格視圖(每個單元格等)。向表格單元格添加數組數據時應用程序崩潰

我正在使用NSXMLParser來獲取信息,並有創建一個數組與選擇我想要的推文。

然而,當我嘗試將它們添加到表格單元格,上線的應用程序崩潰:

cell.textLabel.text = cellValue; 

一個的NSLog這顯示了在應用程序中得到正確的數據在控制檯前,所以我有點難以理解,爲什麼這不起作用。

這是代碼,似乎是有問題的塊:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

// Set up the cell... 
NSString *cellValue = [statuses objectAtIndex:indexPath.row]; 
NSLog(@"%@", cellValue); 


cell.textLabel.text = cellValue; 

return cell;} 

如果它的確與衆不同,我使用ARC和XCode中的最新版本。

我對這一切還是比較陌生的,所以如果我需要提供一些額外的信息,請告訴我。

在此先感謝。

編輯:

回溯給出如下:

* thread #1: tid = 0x2003, 0x918a19c6 libsystem_kernel.dylib`__pthread_kill + 10, stop reason = signal SIGABRT 
frame #0: 0x918a19c6 libsystem_kernel.dylib`__pthread_kill + 10 
frame #1: 0x9968ff78 libsystem_c.dylib`pthread_kill + 106 
frame #2: 0x99680bdd libsystem_c.dylib`abort + 167 
frame #3: 0x03c93e78 libc++abi.dylib`_Unwind_DeleteException 
frame #4: 0x03c9189e libc++abi.dylib`_ZL17default_terminatev + 34 
frame #5: 0x0154df4b libobjc.A.dylib`_objc_terminate + 94 
frame #6: 0x03c918de libc++abi.dylib`_ZL19safe_handler_callerPFvvE + 13 
frame #7: 0x03c91946 libc++abi.dylib`std::terminate() + 23 
frame #8: 0x03c92ab2 libc++abi.dylib`__cxa_throw + 110 
frame #9: 0x0154de15 libobjc.A.dylib`objc_exception_throw + 311 
frame #10: 0x013bdced CoreFoundation`-[NSObject doesNotRecognizeSelector:] + 253 
frame #11: 0x01322f00 CoreFoundation`___forwarding___ + 432 
frame #12: 0x01322ce2 CoreFoundation`_CF_forwarding_prep_0 + 50 
frame #13: 0x0015168f UIKit`-[UILabel setText:] + 56 
frame #14: 0x00003088 Twitter`-[TwitterViewController tableView:cellForRowAtIndexPath:] + 376 at TwitterViewController.m:131 
frame #15: 0x000ace0f UIKit`-[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 494 
frame #16: 0x000ad589 UIKit`-[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 69 
frame #17: 0x00098dfd UIKit`-[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1350 
frame #18: 0x000a7851 UIKit`-[UITableView layoutSubviews] + 242 
frame #19: 0x00052301 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 145 
frame #20: 0x013bde72 CoreFoundation`-[NSObject performSelector:withObject:] + 66 
frame #21: 0x01d6692d QuartzCore`-[CALayer layoutSublayers] + 266 
frame #22: 0x01d70827 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 231 
frame #23: 0x01cf6fa7 QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 377 
frame #24: 0x01cf8ea6 QuartzCore`CA::Transaction::commit() + 374 
frame #25: 0x01d8430c QuartzCore`+[CATransaction flush] + 52 
frame #26: 0x000124c6 UIKit`-[UIApplication _reportAppLaunchFinished] + 39 
frame #27: 0x00012bd6 UIKit`-[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 1324 
frame #28: 0x00021743 UIKit`-[UIApplication handleEvent:withNewEvent:] + 1027 
frame #29: 0x000221f8 UIKit`-[UIApplication sendEvent:] + 68 
frame #30: 0x00015aa9 UIKit`_UIApplicationHandleEvent + 8196 
frame #31: 0x012a6fa9 GraphicsServices`PurpleEventCallback + 1274 
frame #32: 0x013901c5 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53 
frame #33: 0x012f5022 CoreFoundation`__CFRunLoopDoSource1 + 146 
frame #34: 0x012f390a CoreFoundation`__CFRunLoopRun + 2218 
frame #35: 0x012f2db4 CoreFoundation`CFRunLoopRunSpecific + 212 
frame #36: 0x012f2ccb CoreFoundation`CFRunLoopRunInMode + 123 
frame #37: 0x000122a7 UIKit`-[UIApplication _run] + 576 
frame #38: 0x00013a9b UIKit`UIApplicationMain + 1175 
frame #39: 0x0000239d Twitter`main + 141 at main.m:16 
frame #40: 0x00002305 Twitter`start + 53 

調試控制檯顯示此:

2012-04-08 10:10:05.084 Twitter[25309:f803] (
    { 
    text = "Have you shared the Shakedown yet? http://t.co/WHrIC9w7"; 
}, 
    { 
    text = "For all you closet rocknrollas pencil in Sat 12th May The Rebirth of Rock n Roll Party. Haywire Saint @ The Good... http://t.co/OXHKlLIV"; 
}, 
    { 
    text = "4 weeks today: Vocal tracks will be getting recorded at The Premises Studios"; 
}, 
    { 
    text = "Rehearsal tonight in preparation to some big recording next month!"; 
}, 
    { 
    text = "haywire saint 'great taste.' Tune. \n\nhttp://t.co/GKmu5Lna http://t.co/0fii55Hw"; 
}, 
    { 
    text = "Meeting up with an old roadie for The Cure today. oh the stories...... http://t.co/UeUYccme"; 
}, 
    { 
    text = "Satisfying day of programming today.. Haywire Saint app coming along nicely with the custom music player ready to rock 'n' roll!"; 
}, 
    { 
    text = "Happy Friday Everyone!"; 
}, 
    { 
    text = "We had a great time at The Premises Studios yesterday. We'll be back there before long :D x"; 
}, 
    { 
    text = "I posted a new photo to Facebook http://t.co/73qAnCvk"; 
} 
) 

2012-04-08 10:10:05.093 Twitter[25309:f803] { 
text = "Have you shared the Shakedown yet? http://t.co/WHrIC9w7"; 
} 

2012-04-08 10:10:05.094 Twitter[25309:f803] -[__NSCFDictionary isEqualToString:]:  unrecognized selector sent to instance 0x6877a50 
2012-04-08 10:10:05.096 Twitter[25309:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x6877a50' 
*** First throw call stack: 
(0x13bc052 0x154dd0a 0x13bdced 0x1322f00 0x1322ce2 0x15168f 0x3088 0xace0f 0xad589 0x98dfd 0xa7851 0x52301 0x13bde72 0x1d6692d 0x1d70827 0x1cf6fa7 0x1cf8ea6 0x1d8430c 0x124c6 0x12bd6 0x21743 0x221f8 0x15aa9 0x12a6fa9 0x13901c5 0x12f5022 0x12f390a 0x12f2db4 0x12f2ccb 0x122a7 0x13a9b 0x239d 0x2305) 
terminate called throwing an exception2012-04-08 10:10:05.924 Twitter[25309:f803] -[__NSCFConstantString count]: unrecognized selector sent to instance 0x5b30 
+0

這次事故的性質是什麼?回溯是什麼? – 2012-04-08 07:15:27

+0

拍攝,對不起,這是一個線程1:信號sigabrt。我不確定什麼是回溯,但是崩潰並不需要我到main.m,它突出顯示了一行cell.textLabel.text = cellValue;並給我那個錯誤。 – bassmandan 2012-04-08 08:23:28

+0

SIGABRT可能意味着某些斷言被觸發或引發異常。這些細節應該已記錄到調試控制檯。回溯,也稱爲堆棧跟蹤或調用跟蹤,顯示導致程序執行過程中某個點的一系列調用。在調試控制檯中,您可以鍵入「bt」以獲取回溯到此處。 – 2012-04-08 08:53:18

回答

1

statuses陣列似乎舉行字典,不是字符串。每個字典都有一個單一的鍵「文字」。

所以,你可以通過改變線路修復崩潰:

NSString *cellValue = [statuses objectAtIndex:indexPath.row]; 

NSString *cellValue = [[statuses objectAtIndex:indexPath.row] objectForKey:@"text"]; 

或者,如果你以不同的方式構建statuses數組,你可以把它直接包含字符串而不會被不必要地包裝在字典中。不知道你是如何構建它的,很難告訴你如何修復那部分。

+0

這真是太棒了,謝謝,它現在都在工作(我也明白字典和字符串之間的區別!)。我欠你一杯。 – bassmandan 2012-04-08 13:07:49

1

cell.textLabel.text需要NSString *,所以這行之前:

cell.textLabel.text = cellValue; 

嘗試:

NSLog(@"%@", [cellValue class]); 

NSLog(@"%i", [cellValue isKindOfClass:[NSString class]]); 

找出確切的對象類型。

相關問題