您的位置:首页 > 移动开发 > IOS开发

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

2015-06-18 18:58 489 查看
上节:iOS TableView实现QQ好友列表(一)
http://blog.csdn.net/lwjok2007/article/details/46534123
上一节实现了简单的好友列表,但是信息不够丰富,本节将好友的头像,名称,签名等信息全部显示出来



此处我们需要自定义cell

创建一个类 继承

UITableViewCell



添加所需属性

#import <UIKit/UIKit.h>

@interface UserTableViewCell : UITableViewCell

@property (strong,nonatomic) UIImageView *headerphoto;//头像
@property (strong,nonatomic) UILabel *nameLabel;//昵称
@property (strong,nonatomic) UILabel *isOnLine;//是否在线
@property (strong,nonatomic) UILabel *introductionLabel;//个性签名,动态等
@property (strong,nonatomic) UILabel *networkLabel;//网络状态

@end


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

-(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;
}


修改viewcontroller 中tablevew的delegate方法

-(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"];
    cell.isOnLine.text=@"[在线]";
    cell.introductionLabel.text=@"无动态";
    cell.networkLabel.text=@"4G";
    
    return cell;
    
}


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

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

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

如果有问题可加qq讨论

苹果开发群 :414319235 欢迎加入

源代码将在群共享发布
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: