IOS UITableViewCell Uitableviewcontroller Pure Code Development < original >1. Pure code Customization UITableViewCell directly on the code//////#import <UIKit/UIKit.h>@interface Codetableviewcell:uitableviewcell@property (nonatomic, weak) Uiimageview*IconView, @property (nonatomic, weak) UILabel*Labname;+ (Instancetype) Cellwithtableview: (UITableView *) TableView; @end///#import"CodeTableViewCell.h"#defineNjnamefont [Uifont systemfontofsize:15]#defineNjtextfont [Uifont systemfontofsize:16]@implementation Codetableviewcell+ (Instancetype) Cellwithtableview: (UITableView *) TableView {//NSLog (@ "Cellforrowatindexpath"); StaticNSString *identifier =@"Status"; //1. The cache takesCodetableviewcell *cell =[TableView Dequeuereusablecellwithidentifier:identifier]; //2. Create if(Cell = =Nil) {Cell=[[Codetableviewcell Alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:identifier]; } returnCell;} /** * Construction method (called when initializing the object) * Generally add the child controls that need to be displayed in this method*/-(ID) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) Reuseidentifier { self=[Super Initwithstyle:style Reuseidentifier:reuseidentifier]; if(self) {//let the custom cell and the system cell, as soon as it is created, has some child controls available to us to use//1. Create AvatarUiimageview *iconview =[[Uiimageview alloc] init]; [Self.contentview Addsubview:iconview]; Self.iconview=IconView; //2. Create a nicknameUILabel *namelabel =[[UILabel alloc] init]; Namelabel.font=Njnamefont; Namelabel.textcolor=[Uicolor Redcolor]; [Self.contentview Addsubview:namelabel]; Self.labname=Namelabel; [Self.contentview Setbackgroundcolor:[uicolor Clearcolor]; [Self settingframe]; } returnSelf ;}//Set Relative position- (void) settingframe{Self.frame= CGRectMake (0,0, the, -); Self.labName.frame=cgrectmake ( -, -/2- -, $, -); Self.iconView.frame=cgrectmake (Ten, ( -- the)/2, the, the);}- (void) awakefromnib {//Initialization Code}- (void) setselected: (BOOL) selected animated: (bool) animated {[Super setselected:selected animated:animated]; //Configure The View for the selected state} @end//////2. Usually write UITableView in Uiviewcontroller inside define a UITableView, now directly let the current controller inherit from Uitableviewcontroller, avoid writing red tape dead code, more convenient. but table View Controller is limited to managing a full-screen display of Table view. Finally, you need to back up the features of the Lost Table view controller after the migration. Most are viewwillappear: or viewdidappear: a simple statement. Directly on the code: #import<UIKit/UIKit.h>@interface Rootviewcontroller:uitableviewcontroller@end/////#import"RootViewController.h"#import"CodeTableViewCell.h"@interface Rootviewcontroller ()<UITableViewDataSource,UITableViewDelegate>{UITableView*Tableviewmine;} @end @implementation Rootviewcontroller- (void) viewdidload {[Super viewdidload]; Self.view.backgroundColor=[Uicolor Yellowcolor];//Tableviewmine=[[uitableview Alloc]initwithframe:self.view.frame];//[Self.view addsubview:tableviewmine];//tableviewmine.delegate=self;//tableviewmine.datasource=self;}-(void) Viewwillappear: (BOOL) animated{[Super viewwillappear:animated];}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{return -;}-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{return 6;}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpat{//calling a custom TableviewcellCodetableviewcell *cell=[Codetableviewcell Cellwithtableview:tableview]; Cell.labName.text=@"sssssssssss"; Cell.iconView.image=[uiimage imagenamed:@"iconhead.jpg"]; returncell;}-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{NSLog (@"%ld", Indexpath.row);}/*#pragma mark-navigation//in a storyboard-based application, you'll often want to do a little preparation before n avigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new view controller using [s] Egue Destinationviewcontroller]. Pass the selected object to the new view controller.}*/@end///////////
On
IOS UITableViewCell Uitableviewcontroller Pure Code development