0
我有頂部的tableView有三排,現在我想我的小區2移動到的tableView的頂部,這樣小區1變得完全看不見(出的tableView邊界的)滾動一個UITableViewCell的實現代碼如下
這是我的嘗試:
func textViewDidBeginEditing(textView: UITextView) {
let index = NSIndexPath(forItem: 1, inSection: 0)
tableView.scrollToRowAtIndexPath(index, atScrollPosition: .Top, animated: true)
}
上面什麼也沒做,也許我失去了一些東西有
我也試過這樣:
func textViewDidBeginEditing(textView: UITextView) {
let cgpoint = CGPointMake(0, (CGFloat(-64 - (channelCellRowHeight)))) // channelCellRowHeight is the hight of my row which i want move outside the tableview so that cell2 can stay at top of tableview
// here cgpoint is not accurate
tableView.setContentOffset(cgpoint, animated: true)
}
我不知道,必須有更簡單的方法來做到這一點有點像 scrollRowToTop
API
任何線索我如何能實現我想要什麼?
你需要計算你想要移動到頂部的所有單元格的高度,並將它們設置爲你的contentOffset的Y位置 –
你找到了解決方案嗎? –
man我在計算我的行高時遇到了問題,這就是我在做的:'let frame = tableView.rectForRowAtIndexPath(NSIndexPath(forRow:0,inSection:0)) defaultRowHeight = frame.height' @MohammedShakeer但那麼該怎麼做?導致我的默認contentOffset是'(0.0,-64.0)'(當tableView行在他們的默認位置) –