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

UITableView 的 contentSize 何時(shí)設(shè)置?

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

問(wèn)題描述

我在 UIScrollView 中有一個(gè)非滾動(dòng) UITableView.我將 UITableView 的幀大小設(shè)置為其內(nèi)容大小.

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

當(dāng)我向 UITableView 添加一行時(shí),我在 UITableView 上調(diào)用 insertRowsAtIndexPaths:withRowAnimation:.然后我調(diào)用一個(gè)方法來(lái)調(diào)整 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;
}

目前看來(lái),contentSize 尚未更新.如果我在上述方法中根據(jù)行數(shù)和節(jié)數(shù)手動(dòng)計(jì)算框架,則該方法可以正常工作.

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.

我的問(wèn)題是,如何讓 UITableView 更新其 contentSize?我想我可以調(diào)用 reloadData 并且可能會(huì)這樣做,但是當(dāng)我只插入一個(gè)單元格時(shí)重新加載整個(gè)表格似乎效率低下.

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上調(diào)用layoutIfNeeded可以讓UITableView立即計(jì)算出內(nèi)容的大小.這將運(yùn)行所有必要的計(jì)算來(lái)布局 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 子類(lèi)示例,您希望將其放入可變大小的容器視圖中:

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 {}
}

這篇關(guān)于UITableView 的 contentSize 何時(shí)設(shè)置?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Swift - how to get last taken 3 photos from photo library?(Swift - 如何從照片庫(kù)中獲取最后拍攝的 3 張照片?)
Setting contentOffset programmatically triggers scrollViewDidScroll(以編程方式設(shè)置 contentOffset 觸發(fā) scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁(yè)面之間的照片應(yīng)用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動(dòng)時(shí)暫停 NSTimer)
主站蜘蛛池模板: 国产精品欧美日韩 | 午夜精品久久久久久久久久久久久 | 一级全黄少妇性色生活免费看 | 1000部精品久久久久久久久 | 天天插天天干 | 日韩a在线观看 | 99精品在线免费观看 | 久久久一区二区三区四区 | 欧美激情精品久久久久久变态 | 日韩在线大片 | 国内精品99 | 国产精品久久久亚洲 | 99久久精品视频免费 | 午夜免费视频 | 男人天堂色 | 欧美久久久网站 | 久久久国产一区 | 一级毛片视频 | 成人国产在线视频 | 日韩在线视频观看 | 成人国产精品免费观看 | 天天爽综合网 | www九色| 国产成人精品a视频 | 日本久久精品视频 | 欧美1区2区| 91视频免费观看 | 精品亚洲一区二区三区 | 日韩有码一区 | 亚洲精品久久久一区二区三区 | 色999视频 | 精品国产一区二区三区久久久四川 | 电影在线| 日日骚网| 91精品国产91久久久久久吃药 | 激情一区二区三区 | 亚洲日韩第一页 | 91综合在线视频 | 中文字幕一区二区三区在线观看 | 欧美va大片 | 成人欧美一区二区三区1314 |