[IOS development-64] microblogging case practice: Use Code custom cell, the main content is for different heights of cell, ios-64

Source: Internet
Author: User

[IOS development-64] microblogging case practice: Use Code custom cell, the main content is for different heights of cell, ios-64

(1) Effect



(2) download source code and Materials

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


(3) Summary

-- Xib can be used for cell Layout, but the cell height is fixed in this case.

-- If each cell is of different heights, code is needed. The core idea is to calculate the height of the cell Based on the height of the cell's face control.

-- One of the knowledge points used here is to calculate the height and width occupied by a piece of text, that is, to determine the text size. After the text width, you can use a method to calculate the width and height of the text, of course, this method returns many things. size is only one of the attributes.

    CGSize nameMaxSize=CGSizeMake(MAXFLOAT, MAXFLOAT);    NSDictionary *nameAttr=@{NSFontAttributeName:[UIFont systemFontOfSize:14]};    CGSize nameSize=[self.status.name boundingRectWithSize:nameMaxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:nameAttr context:nil].size;

-- Knowledge point 2, because the project's homepage is a rolling view, that is, a tableView, so we can delete the original ViewController of the project and create a tableViewController as the main portal. Set this Controller as the main entry: is Initial View Controller. You just need to check it. (Delete the cell that comes with this controller)



-- The third knowledge point is encapsulation. Models, views, and controllers perform their respective duties.

-- For variables that only provide external access, that is, only those variables of getter, add a readonly variable at @ property to prevent modification by others.

-- 1 and 0 of number data in plist can be directly converted to 0 and 1 of BOOL.

-- In addition to directly using the tableView. cellHeight attribute, the cell height modification proxy method is used in this example.

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{}

-- For some controls, if they exist, they are displayed. If they are not, they are hidden. The hidden attribute is crucial, and the YES and NO values of hidden appear in pairs. Because these cells will be placed in the cache pool, and errors will occur if they are not determined whether to display them again.


Why does the system cell and my custom cell appear simultaneously in ios development?

It doesn't matter if there is no score. They all learn to develop and help each other ~

However, your question is too general. It depends on how the code is written, so a simple description cannot provide the correct answer. Only by sending the detailed code can we see the problem.
 
In ios development, how does the tableView group do it? Write it in complete code,

-(Void) viewDidLoad {[super viewDidLoad]; self. title = @ "personal Settings"; // Do any additional setup after loading the view. [self drawTableView];}-(void) drawTableView {UITableView * tview = [[UITableView alloc] initWithFrame: CGRectMake (0, 0,320, self. view. frame. size. height) style: UITableViewStyleGrouped]; [tview setDelegate: self]; [tview setDataSource: self]; [self. view addSubview: tview];}-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath {return 44;}-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {if (section = 0 | section = 3) {return 2;} return 1;}-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView {return 4;}-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {int section = indexPath. secion; int row = indexPath. row; static NSString * CellIdentifier = @ "Cell"; UITableViewCell * cell = [tableView failed: CellIdentifier]; if (cell = nil) {cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: CellIdentifier]; cell. accessoryType = UITableViewCellAccessoryDisclosureIndicator; switch (section) {case 0: if (row = 0) {cell. textLabel. text = @ "Profile";} else {cell. textLab ...... remaining full text>

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.