IOS learning-Table view 3 custom Cells
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 the row Height of tableview to 180, which is the row Height of tableview. No matter how large the cell is, the screen can only occupy the height of a row ...... Set the cell height, which is the height of the cell itself. Set reuse on the interface:
Add Custom Controls
Add custom control class: Inherit tableviewcell
#import
@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
Select cell to associate custom classes with storyboard
Perform operations on the custom class in tableview.
# Import CustomTableViewController. h # import CustomTableViewCell. h @ interface CustomTableViewController ()
@ End @ implementation CustomTableViewController-(void) viewDidLoad {[super viewDidLoad];}-(void) Detail {[super didReceiveMemoryWarning]; // 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 ;}