iOS TableView实现QQ好友列表(二)

上节:iOS TableView实现QQ好友列表(一)

http://blog.youkuaiyun.com/lwjok2007/article/details/46534123


上一节实现了简单的好友列表,但是信息不够丰富,本节将好友的头像,名称,签名等信息全部显示出来

此处我们需要自定义cell


创建一个类  继承

UITableViewCell




添加所需属性

[objc]  view plain copy
  1. #import <UIKit/UIKit.h>  
  2.   
  3. @interface UserTableViewCell : UITableViewCell  
  4.   
  5.   
  6. @property (strong,nonatomicUIImageView *headerphoto;//头像  
  7. @property (strong,nonatomicUILabel *nameLabel;//昵称  
  8. @property (strong,nonatomicUILabel *isOnLine;//是否在线  
  9. @property (strong,nonatomicUILabel *introductionLabel;//个性签名,动态等  
  10. @property (strong,nonatomicUILabel *networkLabel;//网络状态  
  11.   
  12.   
  13. @end  


重写初始化方法 添加各属性


[objc]  view plain copy
  1. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier  
  2. {  
  3.     self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];  
  4.     if (self) {  
  5.         headerphoto=[[UIImageView alloc]initWithFrame:CGRectMake(1055050)];  
  6.         [self.contentView addSubview:headerphoto];  
  7.           
  8.         nameLabel=[[UILabel alloc]initWithFrame:CGRectMake(60520025)];  
  9.         nameLabel.backgroundColor=[UIColor clearColor];  
  10.         nameLabel.font=[UIFont systemFontOfSize:16];  
  11.         [self.contentView addSubview:nameLabel];  
  12.           
  13.         isOnLine=[[UILabel alloc]initWithFrame:CGRectMake(6040505)];  
  14.         isOnLine.font=[UIFont systemFontOfSize:10];  
  15.         [self.contentView addSubview:isOnLine];  
  16.           
  17.         introductionLabel=[[UILabel alloc]initWithFrame:CGRectMake(120401805)];  
  18.         introductionLabel.font=[UIFont systemFontOfSize:10];  
  19.         [self.contentView addSubview:introductionLabel];  
  20.           
  21.         networkLabel=[[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-5055025)];  
  22.         networkLabel.font=[UIFont systemFontOfSize:10];  
  23.         [self.contentView addSubview:networkLabel];  
  24.     }  
  25.     return self;  
  26. }  



修改viewcontroller 中tablevew的delegate方法


[objc]  view plain copy
  1. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  
  2. {  
  3.       
  4.     NSString *str=[titleArray objectAtIndex:indexPath.section];  
  5.       
  6.     NSArray *arr=[dataDic objectForKey:str];  
  7.       
  8.     static NSString *CellIdentifier = @"UserCell";  
  9.       
  10.     UserTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];  
  11.     cell=nil;  
  12.     if (cell == nil) {  
  13.         cell = [[UserTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];  
  14.           
  15.         cell.selectionStyle = UITableViewCellSelectionStyleGray;  
  16.     }  
  17.       
  18.     NSDictionary *dic=[arr objectAtIndex:indexPath.row];  
  19.     cell.headerphoto.image=[UIImage imageNamed:[dic valueForKey:@"usericon"]];  
  20.     cell.nameLabel.text=[dic valueForKey:@"name"];  
  21.     cell.isOnLine.text=@"[在线]";  
  22.     cell.introductionLabel.text=@"无动态";  
  23.     cell.networkLabel.text=@"4G";  
  24.       
  25.     return cell;  
  26.       
  27. }  

将其中cell修改成自定义的cell 这样就能按照自己想要的样式去实现


此时完成了好友信息的基本展示

下节我们讲继续讲一下如何讲分组折叠起来



如果有问题可加qq讨论  

苹果开发群 :414319235  欢迎加入  

 源代码将在群共享发布


版权声明:本文为博主原创文章,未经博主允许不得转载。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值