QQ interface for iOS
Compile a QQ interface as requested by the master to help me solve the code problem.
Compile a QQ interface with three groups, each of which is attended and shows that the group is online or offline;
Let's take a look.
This saves some trouble because I only use one image. If you want to set it based on different people, you just need to change it in the cell;
Click the group above to expand the content, and then click "retrieve.
Not much nonsense. serving food:
Let's first construct the data:
NSArray * InitArray = @ [@ {@ "Name": @ "friend", @ "Group": @ "YES", @ "Child ": @ [@ {@ "Name": @ "Zhang San", @ "State": @ "online", },{ @ "Name": @ "Wang Wu ", @ "State": @ ""}]}, @ {@ "Name": @ "family", @ "Group": @ "YES", @ "Child ": @ [@ {@ "Name": @ "", @ "State": @ ""}, @ {@ "Name": @ "", @ "State": @ "online"}, @ {@ "Name": @ "", @ "State": @" "}, @ {@ "Name": @ "", @ "State": @ ""}]}, @ {@ "Name": @ "Stranger ", @ "Group": @ "YES", @ "Child": @ [@ {@ "Name": @ "Xiao Wang", @ "State": @ "online "}, @ {@ "Name": @ "Xiao Li", @ "State": @ ""}, @ {@ "Name": @ "xiao hong", @ "State ": @ "exit"}];
Set an array attribute to accept data;
@property (nonatomic,copy) NSMutableArray * CellArray;
Okay. Let's use the data to construct the interface;
The interface is simple:
An image is your own profile picture;
One is your own network name
An online status
The following is a table (tableview)
@interface ViewController (){ UITableView * TableV;}@end
Set a tableview;
Put it inside:
UIImageView * IconImageV = [[UIImageView alloc] initWithFrame: CGRectMake (15, 30, 60, 60)]; IconImageV. image = [UIImage imageNamed: @ "icon.png"]; [self. view addSubview: IconImageV]; UILabel * NameLabel = [[UILabel alloc] initWithFrame: CGRectMake (100, 30,100, 30)]; NameLabel. text = @ "cedar"; NameLabel. textAlignment = 1; // set the text to center in the way [self. view addSubview: NameLabel]; UILabel * StateLabel = [[UILabel alloc] initWithFrame: CGRectMake (100, 60,100, 30)]; StateLabel. text = @ "online"; NameLabel. textAlignment = 1; [self. view addSubview: StateLabel]; TableV = [[UITableView alloc] initWithFrame: CGRectMake (15,100,290,350)]; TableV. delegate = self; TableV. dataSource = self; TableV. separatorStyle = 0; TableV. backgroundColor = [UIColor yellowColor]; [self. view addSubview: TableV];
Then let's 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 want to talk about this tag. I 've been thinking about it for a long time. There is no way to record whether the group is opened or collapsed, finally, we thought that the tag is folded in the format of tag = 1, and opened in the format of tag = 2;
The following are the most difficult methods to fold and 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
The above is a specific way, if you do not understand, then go to view my other blog http://blog.csdn.net/u010123208/article/details/38176943
Okay, the source code of the QQ interface is in
Http://download.csdn.net/detail/u010123208/7774851
Welcome to download