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"];
    [email protected]"[在线]";
    [email protected]"无动态";
    [email protected]"4G";

    return cell;

}

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

先讲到这里,剩余部分下节再讲

如果有问题可加qq讨论

苹果开发群 :414319235  欢迎加入

源代码将在群共享发布

时间: 2024-08-04 15:55:45

iOS TableView实现QQ好友列表(二)的相关文章

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

上节我们讲到如何展示好友信息 iOS TableView实现QQ好友列表(二) http://blog.csdn.net/lwjok2007/article/details/46549111 接下来我们将分组点击的时候折叠起来. 首先新建一个可变字典用来存储当前列表是否展示 NSMutableArray *selectedArr;//控制列表是否被打开 selectedArr=[[NSMutableArray alloc]init]; 根据前两节所讲,我们讲分组名称放在section的heade

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

一,创建项目 二,创建所需属性及实现列表 首先给ViewController创建两个属性 UITableView *tableView;//展示列表 NSArray *titleArray;//第一层列表需要展示的数据 初始化 tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)]; tableView.showsVerticalScrollIndicator=NO; t

tableView练习 -- QQ好友列表

LWTViewController.h // // LWTViewController.h // tableView练习 -- QQ好友列表 // // Created by apple on 14-6-1. // Copyright (c) 2014年 lwt. All rights reserved. // #import <UIKit/UIKit.h> @interface LWTViewController : UITableViewController @end LWTViewCon

[iOS基础控件 - 6.9.3] QQ好友列表Demo TableView

A.需求 1.使用plist数据,展示类似QQ好友列表的分组.组内成员显示缩进功能 2.组名使用Header,展示箭头图标.组名.组内人数和上线人数 3.点击组名,伸展.缩回好友组 B.实现步骤 1.编写MVC结构 (1)根据plist文件结构,编写model,使用嵌套型 1 // 2 // FriendGroup.h 3 // FriendsList 4 // 5 // Created by hellovoidworld on 14/12/12. 6 // Copyright (c) 2014

【iOS基础控件 - 13】【Demo 】QQ好友列表TableView

A.需求 1.使用plist数据,展示类似QQ好友列表的分组.组内成员显示缩进功能 2.组名使用Header,展示箭头图标.组名.组内人数和上线人数 3.点击组名,伸展.缩回好友组 code source: B.实现步骤 1.编写MVC结构 (1)根据plist文件结构,编写model,使用嵌套型 1 // 2 // FriendGroup.h 3 // FriendsList 4 // 5 // Created by hellovoidworld on 14/12/12. 6 // Copyr

iOS-QQ好友列表 iOS 页面间几种传值方式(属性,代理,block,单例,通知)

主要是 点击按钮实现下拉 刷新数据 页面间传值 // // HMFriendsModel.h // QQ好友列表 // // Created by YaguangZhu on 15/9/1. // Copyright (c) 2015年 YaguangZhu. All rights reserved. // #import <Foundation/Foundation.h> @interface HMFriendsModel : NSObject @property(nonatomic,cop

仿QQ好友列表界面的实现

TableView有2种style:UITableViewStylePlain 和 UITableViewStyleGrouped. 但是QQ好友列表的tableView给人的感觉似乎是2个style效果都有,但是tableView不能实现2种效果同时存在. 其实只是用到了Plain这个style,只是在cell的个数显示上做了个处理(个人见解,希望可以帮到有需要的人.....) 当通讯录那一组的cell的组头视图中的button是普通状态下的时候,并不是不显示cell,而是显示一个没有任何内容

UI基础--UITableView实现仿QQ好友列表页面

需求:类似于QQ好友列表页面的显示,有好友分组,有好友数量,在线人数,vip会员.展开分组时显示分组好友,合并分组时不显示:具体效果图如下: 分析: 1.展开分组时显示分组好友,该功能可以使用显示UITableViewCell的数据即可: 2.分组头可以考虑使用一个headerView来实现: 示例文件结构: 具体实现步骤: 1.自定义数据模型类,由于plist文件中包含了2个字典,所以需要写2个数据模型: 2.自定义cell,属性包括数据模型以及生成可重用cell的方法,由于系统自带的子控件即

基于Qt的类似QQ好友列表抽屉效果的实现

前段时间在忙毕业设计,所以一直没有更新博客.今天答辩完以后,将对我的毕业设计进行模块展示,供Qt初学者进行参考. 毕业设计题目:Linux系统下基于Qt的局域网即时通信系统设计与实现 其中我有一个类似于QQ的好友列表,然后对好友可以进行分组管理,毕设中具体效果图如下: 网上查寻到的设计思路: 1.采用QToolBox的方式,虽然看起来有点样子,但是并不是我们所熟悉的好友列表,比如:http://blog.csdn.net/qianguozheng/article/details/6719074