Recently studied some of the basics of HTML5, some C + + foundation, some out of my iOS technology, so I have a lack of confidence in iOS recently, so today began to return to my iOS core technology, the immediate performance as a review of iOS technology, in the form of blog, write a summary, well, nonsense not much to say
Pure code creation: 1. Create TableView
2. Define a custom cell
3. Setting up the agent
4. My implementation of the Proxy method
The creation of TableView is mainly in the following steps:
1. Create TableView
-(void) Createtableview
{
Initializes the TableView and defines the position, size.
UITableView * TableView = [[UITableView alloc]initwithframe:cgrectmake (0, 0, ScreenWidth, screenheight)];
Set the data source and proxy for the table proxy for yourself
Tableview.delegate =self;
Tableview.datasource = self;
Registers the custom cell class for the table. The registration method is as follows
[TableView Registerclass:[mycell class] forcellreuseidentifier:@ "MyCell"];
Join the view.
[Self.view Addsubview:tableview];
}
2. Custom cell
@interface Mycell:uitableviewcell
@property (Nonatomic,strong) UILabel * label;
@property (Nonatomic,strong) uiimageview * image;
@end
@implementation MyCell
-(ID) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) reuseidentifier
{
Self =[super initwithstyle:style reuseidentifier:reuseidentifier];
if (self) {
Self.label =[[uilabel alloc]initwithframe:cgrectmake (0, 0, 20, 30)];
Self.image = [[Uiimageview alloc]initwithframe:cgrectmake (20, 30, 50, 50)];
[Self.contentview AddSubview:self.image];
[Self.contentview AddSubview:self.label];
}
return self;
}
@end
3. Setting up the agent
@interface Mytableviewcontroller ()<UITableViewDelegate,UITableViewDataSource>
4. Implementation of proxy methods:
-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section
{
return 15;
}
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath
{
To set the ID for cell reuse
MyCell * cell = [TableView dequeuereusablecellwithidentifier:@ "MyCell" Forindexpath:indexpath];
If the cell is not created
if (Cell==nil) {
cell= [[MyCell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:@ "MyCell"];
}
Cell.textLabel.text = [NSString stringwithformat:@ "%ld", (long) indexpath.row];
return cell;
}
About custom creation and custom cells for TableView (list) in iOS