Previous section address: http://blog.csdn.net/lwjok2007/article/details/46534123
The previous section implements a simple friend list, but the information is not rich enough, this section will show the friend's avatar, name, signature and other information.
Here we need to customize the cell
To create a class inheritance
UITableViewCell
Add the desired attribute
#import <UIKit/UIKit.h> @interface usertableviewcell:uitableviewcell@property (strong,nonatomic) Uiimageview * headerphoto;//Avatar @property (strong,nonatomic) UILabel *namelabel;//nickname @property (strong,nonatomic) UILabel *isOnLine;/ /whether online @property (strong,nonatomic) UILabel *introductionlabel;//personality signature, dynamic etc @property (strong,nonatomic) UILabel * networklabel;//Network Status @end
Overriding the initialization method to add each property
-(Instancetype) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) reuseidentifier{Self=[super Initwithstyle:style Reuseidentifier:reuseidentifier]; if (self) {Headerphoto=[[uiimageview Alloc]initwithframe:cgrectmake (10, 5, 50, 50)]; [Self.contentview Addsubview:headerphoto]; Namelabel=[[uilabel Alloc]initwithframe:cgrectmake (60, 5, 200, 25)]; Namelabel.backgroundcolor=[uicolor Clearcolor]; Namelabel.font=[uifont Systemfontofsize:16]; [Self.contentview Addsubview:namelabel]; Isonline=[[uilabel Alloc]initwithframe:cgrectmake (60, 40, 50, 5)]; Isonline.font=[uifont Systemfontofsize:10]; [Self.contentview Addsubview:isonline]; Introductionlabel=[[uilabel Alloc]initwithframe:cgrectmake (120, 40, 180, 5)]; Introductionlabel.font=[uifont Systemfontofsize:10]; [Self.contentview Addsubview:introductionlabel]; Networklabel=[[uilabel Alloc]initwithfraMe:cgrectmake (SCREEN_WIDTH-50, 5, 50, 25)]; Networklabel.font=[uifont Systemfontofsize:10]; [Self.contentview Addsubview:networklabel]; } return self;}
Modifying the delegate method of Tablevew in Viewcontroller
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{ NSString *str=[titlearray objectAtIndex:indexPath.section]; Nsarray *arr=[datadic Objectforkey:str]; static NSString *cellidentifier = @ "Usercell"; Usertableviewcell *cell = [TableView dequeuereusablecellwithidentifier:cellidentifier]; Cell=nil; if (cell = = nil) { cell = [[Usertableviewcell alloc]initwithstyle:uitableviewcellstyledefault Reuseidentifier: Cellidentifier]; Cell.selectionstyle = Uitableviewcellselectionstylegray; } Nsdictionary *dic=[arr ObjectAtIndex:indexPath.row]; Cell.headerphoto.image=[uiimage imagenamed:[dic valueforkey:@ "Usericon"]; Cell.namelabel.text=[dic valueforkey:@ "name"]; [Email protected] "[online]"; [Email protected] "no dynamic"; [Email protected] "4G"; return cell; }
Modify the cell into a custom cell so that you can implement the style you want
Let's talk about this, the rest of the section.
If there is a problem can add QQ discussion
Apple Development Group: 414319235 Welcome to Join
The source code will be published in the group share
IOS TableView Implementation QQ Friends List (ii)