Use AutoLayout on iOS7 to allow cell to automatically adjust height

Source: Internet
Author: User

In the case of iOS8, the cell can be automatically resized by adding two more lines after adding a constraint to the cell in storyboard.

1     Self.tableView.estimatedRowHeight = not 0; 2     Self.tableView.rowHeight = uitableviewautomaticdimension;

But now most of the applications are still need to support iOS7, so on the basis above, and then in the TableView agent method to add the following can be resolved, before you forget to add a property

@property (Strong, nonatomic) Sdtableviewcell *ccll;

and initialize

-(void) viewdidload {    [super Viewdidload];     // additional setup after loading the view, typically from a nib.    _CCLL = [Self.tableview dequeuereusablecellwithidentifier:@ "cc"];
Self.tableView.estimatedRowHeight = not 0; Self.tableView.rowHeight = uitableviewautomaticdimension;
}

In the Proxy method:

-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath {Sdtableviewcell*cell = (Sdtableviewcell *) _ccll; Cell.label.text=Arr[indexpath.row];    [Cell setneedsupdateconstraints];    [Cell updateconstraintsifneeded]; Cell.bounds= CGRectMake (0.0f,0.0f, Cgrectgetwidth (tableview.bounds), Cgrectgetheight (cell.bounds));    [Cell setneedslayout];        [Cell layoutifneeded]; CGFloat height=[Cell.contentview systemlayoutsizefittingsize:uilayoutfittingcompressedsize].height; NSLog (@"hei%f", height);//add 1 of the split line, or it'll be almost    returnHeight +1;}

can automatically adjust the height according to the content.

Use AutoLayout on iOS7 to allow cell to automatically adjust height

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.