"Go" IOS via Xib custom UITableViewCell "original"

Source: Internet
Author: User

Original URL: http://blog.it985.com/9683.html

When using TableView, if the cell layout is too complex, it is not intuitive to build through the code. And to constantly adjust the position, font or something. At this time, we can be more intuitive through the xib on the Tableviewcell, effectively improve the development efficiency.
First, after we have created the project, we create a new xib cell. Command+n, choose Cocoa Touch Class

Then select the UITableViewCell type and hook up also Create xib File

After that, we build the style we need on the xib of the corresponding cell.

Then match the corresponding code in the TableView

123456789101112 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    static NSString *cellIndentifier = @"MyTableViewCell";//这里的cellID就是cell的xib对应的名称    MyTableViewCell *cell = (MyTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIndentifier];    if(nil == cell) {        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:cellIndentifier owner:self options:nil];        cell = [nib objectAtIndex:0];    }        _tableView.rowHeight = cell.frame.size.height;//注意,这里我们要把table的rowHeight设为和cell的高度一样    return cell;}

And then we'll see how it works.

Finally, the demo
Custom UITableViewCell via Xib

"Go" IOS via Xib custom UITableViewCell "original"

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.