IOS learning-Table view 3 custom Cells

Source: Internet
Author: User

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 ;}
  

 
 

 

Related Article

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.