#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