使用UItableview在iOS应用开发中实现好友列表功能

2020-01-14 17:58:21于海丽

+(YYfriendCell *)cellWithTableview:(UITableView *)tableView
{
    static NSString *identifier=@"qq";
    YYfriendCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell==nil) {
        //这里使用系统自带的样式
        cell=[[YYfriendCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
        NSLog(@"创建一个cell");
    }
    return cell;
}

-(void)setFriends:(YYFriendsModel *)friends
{
    _friends=friends;
    //1.设置头像
    self.imageView.image=[UIImage imageNamed:_friends.icon];
       //2.设置昵称
    self.textLabel.text=_friends.name;
     //3.设置简介
    self.detailTextLabel.text=_friends.intro;
 //判断是否是会员
    /**
     *  这里有个注意点,如果不写else设置为黑色,会怎么样?
     */
    if (_friends.isVip) {
        [self.textLabel setTextColor:[UIColor redColor]];
    }else
    {
    [self.textLabel setTextColor:[UIColor blackColor]];
    }
}
@end


主控制器部分

 

YYViewController.m文件

复制代码
//
//  YYViewController.m
//  02-QQ好友列表(基本数据的加载)
//
//  Created by apple on 14-5-31.
//  Copyright (c) 2014年 itcase. All rights reserved.
//

 

#import "YYViewController.h"
#import "YYQQGroupModel.h"
#import "YYfriendCell.h"
#import "YYFriendsModel.h"

@interface YYViewController ()
/**
 *  用来保存所有的分组数据
 */
@property(nonatomic,strong)NSArray *groupFriends;
@end


复制代码
@implementation YYViewController
#pragma mark-懒加载
//1.先拿到数据,实现懒加载
-(NSArray *)groupFriends
{
    if (_groupFriends==nil) {