IOS learning-Table view 3 custom cell, ios Cell
Preface
When I read the news today, Kobe slice may retire ahead of schedule. This stubborn man is coming to an end. Although I am not a fan of him, I am also excited, today's topic is based on Kobe Bryant, who pays tribute to this fighter.
We have mentioned the built-in image label of the tableview cell system, which is very convenient to use, but after all, there are many restrictions. This article will talk about a magic thing-custom cells, you can control the content, position, and form displayed by cells. For example, to create a star list, we need four items: profile picture + name + age + gender.
Settings page
Drag Control, such as setting the cell height. Here we will talk about two height:
Set reuse on the interface:
Add Custom Controls
Add 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 custom classes with storyboard
Perform operations on the custom class in tableview.
# Import "mtmtableviewcontroller. h "# import" CustomTableViewCell. h "@ interface mtmtableviewcontroller () <UITableViewDataSource> @ end @ implementation CustomTableViewController-(void) viewDidLoad {[super viewDidLoad];}-(void) didreceivemorywarning {[super busy]; // Dispose of any resources that 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 in the section. return 1;}-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {static NSString * cellIdentifier = @ "Cell"; CustomTableViewCell * cell = [tableView progress: cellIdentifier]; cell. name. text = @ "Kobe"; cell. age. text = @ "37"; cell. phone. text = @ "male"; cell. image. image = [UIImage imageNamed: @ "Kobe.png"]; return cell ;}
Related code
Http://git.oschina.net/zhengaoxing/table1-type
You are welcome to repost. Please indicate the source for reprinting.
Address: http://blog.csdn.net/zhenggaoxing/article/details/43086621
43086621