久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

UITableView 的 contentSize 何時設置?

When does a UITableView#39;s contentSize get set?(UITableView 的 contentSize 何時設置?)
本文介紹了UITableView 的 contentSize 何時設置?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在 UIScrollView 中有一個非滾動 UITableView.我將 UITableView 的幀大小設置為其內容大小.

I have a non scrolling UITableView in a UIScrollView. I set the frame size of the UITableView to its content size.

當我向 UITableView 添加一行時,我在 UITableView 上調用 insertRowsAtIndexPaths:withRowAnimation:.然后我調用一個方法來調整 UITableView 的框架:

When I add a row to the UITableView, I call insertRowsAtIndexPaths:withRowAnimation: on the UITableView. Then I call a method to resize the frame of the UITableView:

- (void)resizeTableViewFrameHeight
{
    // Table view does not scroll, so its frame height should be equal to its contentSize height
    CGRect frame = self.tableView.frame;
    frame.size = self.tableView.contentSize;
    self.tableView.frame = frame;
}

目前看來,contentSize 尚未更新.如果我在上述方法中根據行數和節數手動計算框架,則該方法可以正常工作.

It seems though that the contentSize hasn't been updated at this point. If I manually calculate the frame in the above method based on the number of rows and sections, then the method works properly.

我的問題是,如何讓 UITableView 更新其 contentSize?我想我可以調用 reloadData 并且可能會這樣做,但是當我只插入一個單元格時重新加載整個表格似乎效率低下.

My question is, how can I get the UITableView to update its contentSize? I suppose I could call reloadData and that would probably do it, but it seems inefficient to reload the entire table when I'm just inserting one cell.

推薦答案

UITableView上調用layoutIfNeeded可以讓UITableView立即計算出內容的大小.這將運行所有必要的計算來布局 UITableView.

You can make the UITableView calculate the size of the content immediately by calling layoutIfNeeded on the UITableView. This will run all the necessary calculations to layout the UITableView.

UITableViewController 子類示例,您希望將其放入可變大小的容器視圖中:

Example for a UITableViewController subclass that you want to put in a container view with variable size:

Objective-C

- (CGSize)preferredContentSize
{
    // Force the table view to calculate its height
    [self.tableView layoutIfNeeded];
    return self.tableView.contentSize;
}

斯威夫特

override var preferredContentSize: CGSize {
    get {
        // Force the table view to calculate its height
        self.tableView.layoutIfNeeded()
        return self.tableView.contentSize
    }
    set {}
}

這篇關于UITableView 的 contentSize 何時設置?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Swift - how to get last taken 3 photos from photo library?(Swift - 如何從照片庫中獲取最后拍攝的 3 張照片?)
Setting contentOffset programmatically triggers scrollViewDidScroll(以編程方式設置 contentOffset 觸發 scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁面之間的照片應用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動時暫停 NSTimer)
主站蜘蛛池模板: 欧美日韩中文字幕 | 国产精品久久久久久一区二区三区 | 在线国产一区 | 成人免费看黄网站在线观看 | 国产成人在线视频免费观看 | 国产精品久久久久久久 | 亚洲国产成人精品女人久久久 | 深爱激情综合 | 一区二区三区四区国产 | 亚洲精品电影网在线观看 | 国产成人av一区二区三区 | 韩日一区 | 中文字幕一区二区三区四区 | 久久免费观看视频 | 日日久 | 欧美日韩亚洲视频 | www.亚洲一区二区 | 国产乱人伦精品一区二区 | 97伦理电影网 | 欧美激情区 | 日韩一区在线播放 | 亚洲综合在 | 精品国产伦一区二区三区观看体验 | 欧美日韩一区二区在线播放 | 成人在线一区二区三区 | 欧美高清视频 | 欧美一级欧美三级在线观看 | 婷婷去俺也去 | 一区二区视频在线观看 | 欧美天堂| 日本超碰| 精品久久久久久久人人人人传媒 | 亚洲视频一区在线观看 | 久久国产精彩视频 | 亚洲国产精品一区二区第一页 | 欧美极品在线 | 伊人网在线看 | 亚洲精品粉嫩美女一区 | 亚洲一区欧美 | 成人久久18免费 | 成人深夜福利 |