Customizing the cell division method

Source: Internet
Author: User

#import <UIKit/UIKit.h>

@interface Label_tableviewcell:uitableviewcell
Declare the Uilabel and uiimageview you want to create separately
/**
* Picture
*/
@property (Nonatomic,retain) Uiimageview *headimageview;
/**
* Title
*/
@property (Nonatomic,retain) UILabel *titlelabel;
/**
* Price
*/
@property (Nonatomic,retain) UILabel *pricelabel;
/**
* Evaluation
*/
@property (Nonatomic,retain) UILabel *pingjialabel;
@end
Custom cell (code) ()
-(Instancetype) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) reuseidentifier
{
self = [super Initwithstyle:style reuseidentifier:reuseidentifier];

if (self) {

Add a picture
Self. Headimageview = [[Uiimageview alloc]initwithframe:cgrectmake (0, 0, 100, 100)];

The current View
[Self.contentview addsubview:self. Headimageview];

Add title label
Self.titlelabel = [[UILabel alloc]initwithframe:cgrectmake (100+5, 0, 80, 30)];
Self.titleLabel.backgroundColor = [Uicolor Bluecolor];
[Self.contentview AddSubview:self.titleLabel];

Add a label to a price
Self.pricelabel = [[UILabel alloc]initwithframe:cgrectmake (100+5, 50, 100, 30)];
Self.priceLabel.backgroundColor = [Uicolor Orangecolor];
[Self.contentview AddSubview:self.priceLabel];

Add label for rating
Self.pingjialabel = [[UILabel alloc]initwithframe:cgrectmake (200+60, 0, 80, 30)];
Self.pingjiaLabel.backgroundColor = [Uicolor Redcolor];   [Self.contentview AddSubview:self.pingjiaLabel]; #import "ViewController.h"
#import "Label_tableviewcell.h"
#import "Other_viewcontroller.h"


@interface Viewcontroller () <UITableViewDataSource,UITableViewDelegate>
{
Note In the navigation bar, in the go to write a page, (must initialize a global variable)
Other_viewcontroller *other;
Defines an array of global variables
Nsarray *list;
}

@end

@implementation Viewcontroller

-(void) Viewdidload {
[Super Viewdidload];
[Self loaddata];
Self.view.backgroundColor = [Uicolor Graycolor];

Initialize UITableView
UITableView *tableview = [[UITableView alloc]initwithframe:cgrectmake (0, 0, 300,675)];
Tableview.delegate = self;
Tableview.datasource = self;

Try to be tall.
Tableview.rowheight = 100;
[Self.view Addsubview:tableview];
}


Remove Array
-(void) LoadData
{

Take out the plist data
NSString *path = [[NSBundle mainbundle]pathforresource:@ "AA" oftype:@ "plist"];
List = [Nsarray Arraywithcontentsoffile:path];
}


-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section
{
return 10;
}

-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath
{

Other_viewcontroller *other = [[Other_viewcontroller alloc]init];

Remove the key value from the dictionary.
Represents all rows of the entire UITableView
Take out the contents of the array
Other.text = list[indexpath.row][@ "a"];
NSLog (@ "%@", Other.text);

Jump back to the next page
[Self.navigationcontroller Pushviewcontroller:other Animated:yes];
}



-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath
{
NSString *cellid = @ "Cellid";
Label_tableviewcell *cell = [TableView dequeuereusablecellwithidentifier:cellid];

if (!cell) {
cell = [[Label_tableviewcell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:cellid];
}
Cell.detailTextLabel.text = @ "Good summary";
cell.textlabel.text= @ "Memories";
Cell.imageView.image = [UIImage imagenamed:@ "22.jpg"];
Every single button in every line.
Cell. Headimageview.image = [UIImage imagenamed:@ "22.jpg"];
Cell.titleLabel.text = @ "Memory";
Cell.pingjiaLabel.text = @ "Learning";
Cell.priceLabel.text = @ "Dream scar";

return cell;}

Customizing the cell division method

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.