2010-05-26 95 views
5

我試圖滾動我的tableview到第二小區:的UITableView不會滾動到細胞

[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0] 
            atScrollPosition:UITableViewScrollPositionNone 
              animated:NO]; 

我得到的錯誤:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]: section (1) beyond bounds (0). 

'

我tableview中有30個細胞那些沒有部分出現。

+0

顯示'numberOfSectionsInTableView'的代碼:' – 2010-06-01 20:07:07

回答

3

如果你沒有的部分,那麼你可以嘗試indexPathWithIndex:類的構造函數:

[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathWithIndex:1] 
         atScrollPosition:UITableViewScrollPositionNone 
           animated:NO]; 
+0

該調用在4.0中不推薦使用。我知道我們不能討論它,所以如果不打破NDA,我怎麼能指定一個部分,如果我不包含任何? – 2010-05-26 13:58:56

+0

@Sheehan:我看不到XCode,頭文件或文檔中的棄用警告。你確定這個電話已被棄用嗎? – 2010-05-26 14:34:30

+1

對不起,我錯了,不推薦使用。我確實得到這個錯誤: ***終止應用程序,由於未捕獲的異常'NSInternalInconsistencyException',原因:'與UITableView一起使用的索引路徑無效。傳遞給表視圖的索引路徑必須包含恰好兩個指定節和行的索引。如果可能,請在UITableView.h中使用NSIndexPath上的類別。' – 2010-05-26 15:04:28

0

我建議你創建一個部分,將細胞儲存在該節可以沒有標題,使其看起來並不區分。 ,這對你來說有什麼好處,就是不必打擊預期的API途徑。

NSIndexPath *ip = [NSIndexPath indexPathForRow:itemCurrentlyPlaying inSection:0]; 

這並不容易找到,但相關的便捷構造:

2

像pollyp,我能夠使用indexPathForRow:inSection:。我從我的viewWillAppear:打電話給我。

它看起來像你的錯誤信息是說,甚至沒有一節。您是否可以在載入表格數據之前調用scrollToRowAtIndexPath:atScrollPosition:animated:(例如,在viewDidLoad)?請稍後嘗試撥打電話,地址爲viewWillAppear: