iOS Learning-table View 3 custom cells

Source: Internet
Author: User

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:
  1. 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 ...
  2. 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

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.