亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

動態更改UITableView高度

動態更改UITableView高度

慕容708150 2019-08-30 15:56:51
我想基于其單元格高度的總和從另一個viewcontroller更改tableview的高度,因為它們是動態的。它可能嗎?謝謝添加在:我基本上擁有一個UserProfileViewController,它在屏幕的一半上有一個容器視圖。在那里我添加了不同的其他viewcontrollers:在wall按鈕的情況下,這是我添加viewcontroller的方式,它是后續的tableview:- (IBAction)wallButtonPressed:(id)sender{    //Check if there is an instance of the viewcontroller we want to display. If not make one and set it's tableview frame to the container's view bounds    if(!_userWallViewController) {        self.userWallViewController = [[WallViewController alloc] init];//        self.userWallViewController.activityFeedTableView.frame = self.containerView.bounds;    }    [self.userWallViewController.containerView addSubview:self.userWallViewController.activityFeedTableView];    //If the currentviewcontroller adn it's view are already added to the hierarchy remove them    [self.currentViewController.view removeFromSuperview];    [self.currentViewController removeFromParentViewController];    //Add the desired viewcontroller to the currentviewcontroller    self.currentViewController = self.userWallViewController;    //Pass the data needed for the desired viewcontroller to it's instances    self.userWallViewController.searchURLString = [NSString stringWithFormat:@"event/user/%@/", self.userID];    self.userWallViewController.sendCommentURLString = [NSString stringWithFormat:@"event/message/%@", self.userID];    [self.userWallViewController.activityFeedTableView reloadData];    self.userWallViewController.totalCellHeight = ^(float totalCellHeight){在那個viewcontroller中,這是我初始化tableview的地方:-(UITableView *)activityFeedTableView{    if (!_activityFeedTableView) {        _activityFeedTableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 850.0) style:UITableViewStylePlain];    }    return _activityFeedTableView;}我正在計算單元格高度的總和,問題是在調用te tableview的getter之后調用單元格的高度方法。因此,我需要某種方式來了解何時為所有細胞完成細胞的高度方法,然后我可以調整我的tableview。謝謝
查看完整描述

3 回答

?
繁星淼淼

TA貢獻1775條經驗 獲得超11個贊

通過xib或storyboard創建您的單元格。給出它的出口內容?,F在在CellForRowAtIndexPath中調用它。例如。如果要根據Comment的標簽文本設置單元格高度。 在此輸入圖像描述


所以設置你的commentsLbl.numberOfLine = 0;


所以設置你的commentsLbl.numberOfLine = 0;


然后在ViewDidLoad中


 self.table.estimatedRowHeight = 44.0 ;

self.table.rowHeight = UITableViewAutomaticDimension;

現在


-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

return UITableViewAutomaticDimension;}


查看完整回答
反對 回復 2019-08-30
?
一只斗牛犬

TA貢獻1784條經驗 獲得超2個贊

這里的許多答案都不尊重桌子的變化或太復雜。使用autolayout時,使用UITableView正確設置的子類intrinsicContentSize是一個更容易的解決方案。不需要高度限制等。


class UIDynamicTableView: UITableView

{

    override var intrinsicContentSize: CGSize {

        self.layoutIfNeeded()

        return CGSize(width: UIViewNoIntrinsicMetric, height: self.contentSize.height)

    }


    override func reloadData() {

        super.reloadData()

        self.invalidateIntrinsicContentSize()

    }

UIDynamicTableView在接口構建器中設置TableView的類并觀察魔法,因為此TableView將在調用后更改其大小reloadData()。


查看完整回答
反對 回復 2019-08-30
  • 3 回答
  • 0 關注
  • 716 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號