"iOS Development-64" Weibo case exercise: Customizing cells with code, primarily for cells of different heights

Source: Internet
Author: User

(1) Effect



(2) Source code and material download

http://download.csdn.net/detail/wsb200514/8089727


(3) Summary

--You can use the Xib layout cell, but the cell time fixed height of this case

--If each cell is at a different height, the code needs to be used, and the core idea is to calculate the cell's height based on the height of the child controls inside the cell.

--one of the knowledge points used here, to calculate a paragraph of the high-width occupied by text, is to determine the text size, text width, you can use a method to calculate the width of the text, of course, this method returns a lot of things, size is just one of the attributes.

    Cgsize Namemaxsize=cgsizemake (Maxfloat, maxfloat);    Nsdictionary *[email Protected]{nsfontattributename:[uifont systemfontofsize:14]};    Cgsize namesize=[self.status.name boundingrectwithsize:namemaxsize Options:nsstringdrawinguseslinefragmentorigin Attributes:nameattr context:nil].size;

--The second point of knowledge, because this project opens the homepage is a scrolling view is a tableview, so we can delete the original viewcontroller of the project, create a tableviewcontroller as the main entrance. This controller as the main entrance is set to: is Initial View controller, Hook can be. (Remove the cell that comes with this controller)



--three of the points of knowledge, or encapsulation. Models, views, and controllers perform their duties.

--For variables that provide only outside access, that is, those variables with getter only, add a readonly at @property to prevent others from modifying them.

1 and 0 of the number type data inside the--plist can be converted directly to bool 0 and 1.

--Modify the cell height in addition to the direct use of tableview.cellheight this attribute, there is a proxy method, is the method used in this example.

-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{}

-For some controls, if there is something to show, if there is no hidden, this inside hidden property is very important, and Hidden's Yes and no is best to appear in pairs. Because these cells are placed in the cache pool, they will be faulted if not judged if they are not displayed again when they are removed.

"iOS Development-64" Weibo case exercise: Customizing cells with code, primarily for cells of different heights

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.