Write in front
Today, watching the news, Kobe Bryant shoulder tear, may be retired early, the stubborn man, finally to the end, although I am not his fans, but also the heart of admiration, today's theme to Kobe as material, to the life of the fighters salute.
We talked about the TableView cell system comes with the image label, it is very convenient to use, but after all a lot of restrictions, this one will talk about a magical thing--custom cells, by you control the contents of the cell display, location, form. For example, we want to create a list of stars, need four information: Avatar + name + age + Gender
Setup interface
Drag a control, such as Setting the height of a cell, here to say the height has two:
- Set the row height of the TableView to: 180 This height is tableview high, that is, no matter how big the cell you want, the screen can only occupy a line of height ...
- Set the cell height, which is the height of the cell itself
In the interface settings reuse:
To add a custom control class
To add a custom control class: Inherit Tableviewcell
<span style= "FONT-SIZE:14PX;" > #import <UIKit/UIKit.h> @interface customtableviewcell:uitableviewcell@property (weak, nonatomic) Iboutlet Uiimageview *image; @property (weak, nonatomic) Iboutlet UILabel *name; @property (weak, nonatomic) Iboutlet UILabel *age;@ Property (weak, nonatomic) Iboutlet UILabel *phone; @end </span>
Select cell to associate the custom class and storyboard
In TableView, you can work with a custom class
#import "CustomTableViewController.h" #import "CustomTableViewCell.h" @interface Customtableviewcontroller () < Uitableviewdatasource> @end @implementation customtableviewcontroller-(void) viewdidload {[Super viewDidLoad];} -(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} #pragma mark-table View data source-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {//Return the Number of sections. return 1;} -(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {//Return the number of rows The section. return 1;} -(uitableviewcell*) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{static NSString *[email protected] "Cell"; Customtableviewcell*cell=[tableview Dequeuereusablecellwithidentifier:cellidentifier]; [email protected] "Kobe Bryant"; [email protected] "37"; [email protected] "male"; CEll.image.image=[uiimage imagenamed:@ "Kobe.png"]; return cell;}
Related code
Http://git.oschina.net/zhengaoxing/table1-type
Welcome reprint, Reprint please indicate the source
This address: http://blog.csdn.net/zhenggaoxing/article/details/43086621
43086621
iOS Learning-table View 3 custom cells