IOS implementation QQ Interface

Source: Internet
Author: User

Should master request to write a QQ interface to be generous to enlighten me under the code problem.

Write a QQ interface. There are three groups, each with a group of people. and shows online not on the line.

Check it out first.

Save it here. Because my picture just took one. Suppose to be based on a person's different settings, just to change within the cell can be;

The main is to achieve click on the above group to expand the content, and then click Retract.

Needless to say, serving:

Let's start by constructing the data:

 Nsarray * Initarray [email protected][@{@ "Name": @ "Friends",                                       @ "Group": @ "YES" @ "Child": @[ @{@ "Name": @ "Zhang San", @ "state": @ "Online",}, @{@ "Nam                               E ": @" Harry "@" state ": @" Leave "}] }, @{@ "Name": @ "Family" @ "Group": @ "YES" @ "Child": @[@{@ "Name": @ "sister" @ "Sta" TE ": @" Online "}, @{@" Name ": @" sister "@" state ": @ "Online"}, @{@ "Name": @ "brother", @ "state": @ "leave                     "},                     @{@ "Name": @ "brother" @ "state": @ "Leave"}] }, @{@ "Name": @ "Stranger", @ "Group"                                         : @ "YES" @ "Child": @[@{@ "Name": @ "Xiao Wang",                                         @ "state": @ "Online"}, @{@ "Name": @ "Xiao Li",                                         @ "state": @ "Leave"}, @{@ "Name": @ "Little Red", @ "state": @ "Leave"}]}];

Set an array property to accept the data;

@property (nonatomic,copy) nsmutablearray * Cellarray;

Well, let's use the data to construct the interface.

The interface is very easy:

A picture is one's own avatar;

One is your own web name.

An online status

Here is a table (TableView)

@interface Viewcontroller () {    UITableView * Tablev;} @end

Set a tableview;

Put it inside:

Uiimageview *iconimagev = [[[Uiimageview alloc]initwithframe:cgrectmake];    Iconimagev.image = [UIImage imagenamed:@ "Icon.png"];    [Self.view Addsubview:iconimagev];    UILabel *namelabel = [[UILabel alloc]initwithframe:cgrectmake (+, +, +)];    Namelabel.text = @ "Cedar";    Namelabel.textalignment = 1;//Sets the way the text is centered     [Self.view Addsubview:namelabel];    UILabel *statelabel = [[[UILabel alloc]initwithframe:cgrectmake];    Statelabel.text = @ "Online";    Namelabel.textalignment = 1;    [Self.view Addsubview:statelabel];        Tablev = [[UITableView alloc]initwithframe:cgrectmake (290, +)];    Tablev.delegate = self;    Tablev.datasource = self;    tablev.separatorstyle=0;    Tablev.backgroundcolor =[uicolor Yellowcolor];    [Self.view Addsubview:tablev];

And then we're going to construct the table.

-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{        UITableViewCell *cell;    Nsdictionary * dectionary = [_cellarray objectAtIndex:indexPath.row];    if ([Dectionary objectforkey:@ "Group"])    {        cell = [[UITableViewCell alloc]initwithstyle: UITableViewCellStyleValue2 reuseidentifier:@ "Group"];        Cell.textLabel.text = [Dectionary objectforkey:@ "Name"];        cell.textlabel.textalignment=0;        Cell.backgroundcolor = [Uicolor graycolor];        Cell.tag = 1;    }    else    {        cell = [[UITableViewCell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:@ "Child "];        Cell.imageView.image = [UIImage imagenamed: @ "Icon.png"];        Cell.textLabel.text = [Dectionary objectforkey:@ "Name"];        Cell.detailTextLabel.text = [dectionary objectforkey:@ "State"];    }    return cell;    }

Here I would like to say. This tag. I thought for a very long, how to record whether this group is open or folded. There is no way, the last thought of the tag with tag=1 means folding. =2 said to be open;

The hardest part of the following is the way it folds open.

-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{nsmutabledictionary *        Dictionary = [nsmutabledictionary dictionarywithdictionary:[_cellarray ObjectAtIndex:indexPath.row]];    UITableViewCell *cell = [Tablev Cellforrowatindexpath:indexpath];    NSLog (@ "%@", Cell.textLabel.text);        if ([Dictionary objectforkey:@ "Group"]) {Nsarray *childarray = [Dictionary objectforkey:@ "Child"];                Nsmutablearray *patharray = [Nsmutablearray array];            if (cell.tag==1) {cell.tag=2;                for (int i =0; i<childarray.count;i++) {dictionary = [Childarray objectatindex:i];                [_cellarray insertobject:dictionary atindex:i+indexpath.row+1];                Nsindexpath *path = [Nsindexpath indexpathforrow:i+indexpath.row+1 insection:0];            [Patharray Addobject:path]; } [Tablev Insertrowsatindexpaths:patharray Withrowanimation:uitableviewroWanimationautomatic];            } else {cell.tag=1;            Nsmutableindexset * deleteset= [Nsmutableindexset indexset];                For (Nsdictionary *dic in Childarray) {Nsinteger row= [_cellarray indexofobject:dic];                Nsindexpath * Path = [Nsindexpath indexpathforrow:row insection:0];                [Patharray Addobject:path];            [Deleteset Addindex:row];            } [_cellarray Removeobjectsatindexes:deleteset];        [Tablev Deleterowsatindexpaths:patharray Withrowanimation:uitableviewrowanimationbottom]; }    }    }

Above is the detailed way. If you don't understand, then go and see my other blog http://blog.csdn.net/u010123208/article/details/38176943

All right. The source code of the QQ interface

http://download.csdn.net/detail/u010123208/7774851

Welcome to download

IOS implementation QQ Interface

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.