2014-10-08 32 views
2

我在嘗試使用swift學習iOS開發,並遇到了一些我找不到解決方案的方法。豎起大拇指直到UITableView中的最後一個項目

我想修改一個UITableView,這樣我就可以向上滾動,直到最後一項爲例如。有這樣的:

enter image description here

我希望能夠,直到最後一個項目顯示在第一行向上滾動,並停留在那裏,不得超生(像這樣):

enter image description here

或者是否有任何其他類型的控件爲我提供此功能?

+0

你只需[設定內容偏移(HTTPS: //developer.apple.com/library/ios/documentation/Uikit/reference/UIScrollView_Class/index.html#//apple_ref/occ/instm/UIScrollView/setContentOffset:animated :) – Daniel 2014-10-08 11:28:22

+0

所以現在的問題是最後一個單元格是無法顯示? – gabbler 2014-10-08 12:00:40

回答

1

試試這個代碼:

CGFloat rowHeight = 40 /* YOUR ROW HEIGHT */ * [self.items count]; 
[self.tableView setContentOffset:CGPointMake(0, rowHeight) animated:YES]; 
// Here self.items is your datasource array 
0
如果要滾動到最後一排

, 談話陣列使用:

long row=conversation.count-1; 
if (conversation.count >1) { 
    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES]; 
} 
相關問題