IOS uses TableView to implement a personal hub list

Source: Internet
Author: User

A similar personal center can be implemented using UITABLEVIEWL.

Final effect



Directly on the code


First make

Uiviewcontroller

Implementation protocol

Uitableviewdatasource , uitableviewdelegate

Create two properties


UITableView *personaltableview;

Nsarray *datasource;



@interface Userinfoviewcontroller () <uitableviewdatasource,uitableviewdelegate>{    UITableView * Personaltableview;    Nsarray *datasource;    }


Initialization


Personaltableview=[[uitableview alloc]initwithframe:cgrectmake (0, 44+20, Screen_width, SCREEN_HEIGHT-20-44-49) Style:uitableviewstylegrouped];    [Self.view Addsubview:personaltableview];    personaltableview.delegate=self;    personaltableview.datasource=self;    Personaltableview.bounces=no;    Personaltableview.showsverticalscrollindicator = no;//does not display the right slider    personaltableview.separatorstyle= uitableviewcellseparatorstylesingleline;//Split Line    [email protected][@ "My share", @ "password management", @ "User Agreement" @ "about"];

Implement a few proxies


#pragma mark tableviewdelegate-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{//number of groups that is, section re Turn 3;} Set the number of TableView under each grouping-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteger) section{if (    section==0) {return 1;    }else if (section==1) {return datasource.count;    }else{return 1; }}//blank height reserved on top of each group-(cgfloat) TableView: (UITableView *) TableView heightforheaderinsection: (nsinteger) section{return 20;} Blank height reserved below each group-(cgfloat) TableView: (UITableView *) TableView heightforfooterinsection: (Nsinteger) section{if (    section==2) {return 40; } return 20;} The corresponding TableView height in each packet-(cgfloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *)    indexpath{if (indexpath.section==0) {return 80; } return 40;} Set the cell corresponding to each row (UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{Static NSString *[email protEcted] "cell";    UITableViewCell *cell=[tableview Dequeuereusablecellwithidentifier:identifer];     if (cell==nil) {Cell=[[uitableviewcell alloc]initwithstyle:uitableviewcellstyledefault reuseIdentifier:identifer]; } if (indexpath.section==0) {Cell=[[uitableviewcell Alloc]initwithstyle:uitableviewcellstyledefault Reu                seidentifier:@ "UserInfo"];        Uiimageview *imageview=[[uiimageview Alloc]initwithframe:cgrectmake (12, 0, 80, 80)];        Imageview.image=[uiimage imagenamed:@ "Usericon.png"];                [Cell.contentview Addsubview:imageview];        UILabel *namelabel=[[uilabel alloc]initwithframe:cgrectmake (100, 0, 60, 80)];        [email protected] "Li Chen";    [Cell.contentview Addsubview:namelabel];    }else if (indexpath.section==1) {Cell.textlabel.text=[datasource ObjectAtIndex:indexPath.row];        }else{[email protected] "Exit login";    Cell.textlabel.textalignment=nstextalignmentcenter; } return cell;

So far the whole interface has been basically implemented




If there is a problem can add QQ discussion

Apple Development Group: 414319235 Welcome to Join


UiviewcontrollerUitableviewdatasource,uitableviewdelegate

IOS uses TableView to implement a personal hub list

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.