2011-11-02 90 views
0

我正在使用scrollToRowAtIndexPath將我的tableview放置在之前選定的單元格中心,但是它在測試手機時崩潰了應用程序,但在模擬器上未進行測試。scrollToRowAtIndexPath在設置我的tableview之前檢查indexpath

這是我如何設置它

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
    //Center previously selected cell to center of the screen 
    [self.tableView reloadData]; 
    [self.tableView scrollToRowAtIndexPath:oldCheckedIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO]; 
} 

並且這是它給

*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]: section (0) beyond bounds (0).' 
*** First throw call stack: 
(0x31fe88bf 0x31d581e5 0x31fe87b9 0x31fe87db 0x32b6df1f 0x29bef 0x32ae26b5 0x32b3daf1 0x32afed21 0x32afea71 0x32afe78b 0x32afe4ff 0x32ab581b 0x32abafb9 0x3193aba7 0x3273be8d 0x31fbb2dd 0x31f3e4dd 0x31f3e3a5 0x3204afed 0x32ace743 0x34f5 0x2f70) 
terminate called throwing an exception(gdb) 

錯誤的事情的存在是我在不同的方法設置

[self.tableView reloadData]; 
     [self.tableView scrollToRowAtIndexPath:oldCheckedIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO]; 

的應用程序工作正常,但不會滾動到索引位置.. 我不知道如何解決它。

更新新的錯誤時,試圖拖延scrollToRowAtIndexPath

2011-11-02 16:00:58.180 code[2303:707] -[VehicleResultViewController methodThatCallsScrollToRow]: unrecognized selector sent to instance 0x1f3410 
2011-11-02 16:00:58.184 code[2303:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[VehicleResultViewController methodThatCallsScrollToRow]: unrecognized selector sent to instance 0x1f3410' 
*** First throw call stack: 
(0x31fe88bf 0x31d581e5 0x31febacb 0x31fea945 0x31f45680 0x35bef943 0x31fbca63 0x31fbc6c9 0x31fbb29f 0x31f3e4dd 0x31f3e3a5 0x3204afed 0x32ace743 0x34a9 0x2f24) 
terminate called throwing an exception(gdb) 

回答

4

你可能不需要重新加載數據 - 只是一個延遲後運行scrollToRowAtIndexPath:

[自performSelector:@selector(methodThatCallsScrollToRow) withObject:nil afterDelay:2.5];

給表格加載的機會。

+0

奇怪..我不知道爲什麼會發生這種情況,但在將這行代碼放入後,我開始出現上面每次嘗試訪問子視圖時都添加的錯誤。 –

+0

哈哈血腥地獄!大聲笑** methodThatCallsScrollToRow **大聲笑..多數民衆贊成什麼c使用錯誤..事情是滾動代碼裏面viewDidAppear方法 –

+0

真棒!完美地工作!你我的朋友應該得到高五!大聲笑我整天跟蹤我的實際問題..這解決了很好,我把時間降到0.5,它動畫很好。我想我會添加一個小裝載thingy,讓這真的看起來是正確的用戶....非常酷謝謝 –

相關問題