[iOS base Control-6.6.1] show buy data code [iOS base Control-6.7] Weibo show use code custom TableCell (dynamic size)

Source: Internet
Author: User
Tags uikit

A. Requirements 1. Similar to Weibo content display 2. Avatar 3. Name 4. member symbol 5. Content 6. Split Line 7. Picture (optional, dispensable) b. Ideas, step 1. Controller:uitableviewcontroller change controller inherits from Uitableviewcontroller,storyboard and also uses the new Tableviewcontroller, Its tableview as the starting entry. 2.View: Code custom cell uses code to assemble each cell, dynamically change the position of the control, the size of the cell contains a member property of the Weiboframe type to hold the data, the position size 3.Model: (1) Weibo: The data model saves every micro-blog Data (2) The Weiboframe:frame model holds a Weibo member property, the position size of each control, and the height of the cell C. Implementation point 1. Using Uitableviewcontroller as controller and UITableView as the UITableView member, the default proxy and DataSource are Uitableviewcontrollerself.view = = Self.tableview-> The current controller inherits Uitableviewcontroller, and then specifies the view's class, Xcode automatically configures (1) Inheritance Uitableviewcontroller
1 //2 //ViewController.h3 //Weibo4 //5 //Created by Hellovoidworld on 14/12/4.6 //Copyright (c) 2014 Hellovoidworld. All rights reserved.7 //8 9 #import<UIKit/UIKit.h>Ten  One //Specifies that the controller inherits from Uitableviewcontroller A @interfaceViewcontroller:uitableviewcontroller -  -  the @end
(2) Delete the original Uiviewcontroller (3) in the interface design and drag it into a new Uitableviewcontroller (4) configuration Class (5) Setting Uitableviewcontroller to entry point (5) Xcode automatically configures DataSource and delegate 2. Custom cell (child controls within the cell are not fixed) do not use Xib, use code
    • Create a new class that inherits from UITableViewCell
    • Add all the child controls that need to be displayed in the cell's constructor Initwithstyle:reuseindentifier: (You don't need to set frame and data)
    • Provide a model property in the header file
    • Override the setter of the model property to set the view and frame data in this method
1. Custom cell via Xib
* Add TableView
* Load Group Purchase data
* New Xib, get child controls
* Package
* Finally introduced Headerview and Footerview (insert AD, load more)

2. Through the Code customization cell* introduced uitableviewcontroller* load model data Weibo, with the cell to show the basic data * Create a new Weibocell, encapsulate the model data * Add 4 child controls to the Init method
* Set data to child controls in the Set method
* Calculating frame* for child controls in set method The height of the cell cannot be calculated * Design weiboframe* establish Weibo, weboframe, Weibocell relationship (Reminder attribute name cannot be called frame) * Performance optimization (storing weiboframe data, not storing Weibo data) 3.frame ModelsSet the frame for each child control in the cell: the setter in the Weibo model reference that was held in the previous cell is divided into two parts: setting the View data and setting the frame (1) Creating a spacing variable (2) The first line: Avatar, nickname,     Use spacing to set the appropriate position (3) Calculate the size of the nickname, pass in the maximum size, the font, the height and width of the frame used to calculate the nickname, create a method to process a text of size (4) Set member icon (5) Calculate body size A. Calculate its size to calculate its frame;
1 // use the Self-band method to calculate the size occupied by a piece of text 2 -(cgsize) Caltextsizewithtext: (NSString *) text font: (Uifont *) font maxSize: (cgsize) maxSize {3      nsdictionary *attrs = @{nsfontattributename:font}; 4    5     return [text boundingrectwithsize:maxsize options:nsstringdrawinguseslinefragmentorigin attributes:attrs context:nil ].size; 6 }

B. Set the line wrap; textview.numberoflines = 0;//Set the line wrap (6) with the map, set the size of the map, calculate the position (7) Calculate the height of the cell, there is a map from the map, no map from the blog

[iOS base Control-6.6.1] show buy data code [iOS base Control-6.7] Weibo show use code custom TableCell (dynamic size)

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.