IOS TableView Implementation QQ Friends List (ii)

Source: Internet
Author: User

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)

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.