仿QQ空间用一个tableview显示多种自定义cell
2019独角兽企业重金招聘Python工程师标准>>>
第一部分 要实现效果
先来看看真实QQ空间的效果吧:
从这张截图中,可以看到两种自定义的cell,其实在QQ空间的我的空间中有三种自定义的cell,那么这就是我们要实现的效果。
第二部分 实现的思路
第一步(由于没有数据源,我们只好操作plist文件):
创建我们所需要的plist文件,如下图:
这是表格样式三所需的plist文件
这是我们表格样式一所需的plist文件
这是表格样式二所需要的文件
第二步 有了素材文件之后,就好办了,我们需要把它解析出来,由于这些plist文件都是以数组形式包装的,所以在解析出来的时候,我们要用数组给他们保存起来,所以我们在头文件中声明了这三个数组
第三步 加载并保存plist文件
第四步 控制器成为表格的代理和数据源,并实现数据源相应的方法
第五步 实现表格的返回section的分区数的这个方法,这个很重要,也是实现我们今天的这个效果的关键部分之一
由于我们需要实现三个自定义的cell,所以在这里返回3就行了,如果你想返回很多个分区,你在这里写上你想要的分区数就行了
第六步 返回每个分区表格的行数,由于有三个分区,需要作相应的判断,方法如下
第七步 返回每个分区中表格中每行返回的要显示的cell
第八步 返回分区中每行表格需要显示的行高,不要忘了这个方法哦,不然表格不会正常的显示出来,而是显示默认的44的高度
第三部分 程序实现的效果
好了,思路大概就是那样的了,现在来看看我们的结果吧
第四部分 源码
为了方便大家学习,我把源码复制上来
// 多样式的表格
//
// Created by 妖精的尾巴 on 15-10-16.
// Copyright (c) 2015年 妖精的尾巴. All rights reserved.
//
#import "ViewController.h"
#import "LHZoneCell.h"
#import "mySpaceCell.h"
#import "gameCell.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
/**
*存储qqZoneDataplist的文件数组
*/
@property(nonatomic,strong)NSArray* plistDataArray;
/**
*存储mySpaceplist的文件数组
*/
@property(nonatomic,strong)NSArray* plistArray;
/**
*存储playPlist的文件数组
*/
@property(nonatomic,strong)NSArray* playArray;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self createTable];
[self loadPlistData];
}
-(void)loadPlistData
{
NSString* pathFile=[[NSBundle mainBundle]pathForResource:@"qqZoneData.plist" ofType:nil];
self.plistDataArray=[NSArray arrayWithContentsOfFile:pathFile];
NSString* path=[[NSBundle mainBundle]pathForResource:@"mySpace.plist" ofType:nil];
self.plistArray=[NSArray arrayWithContentsOfFile:path];
NSString* pFile=[[NSBundle mainBundle]pathForResource:@"play.plist" ofType:nil];
self.playArray=[NSArray arrayWithContentsOfFile:pFile];
}
-(void)createTable
{
UITableView* tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
tableView.delegate=self;
tableView.dataSource=self;
[self.view addSubview:tableView];
}
#pragma mark - 表格数据源方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0) {
return self.plistArray.count;
}else if(section==1){
return self.plistDataArray.count;
}else{
return self.playArray.count;
}
}
-(UITableViewCell* )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
NSString* cellw=@"c";
mySpaceCell* cell=[tableView dequeueReusableCellWithIdentifier:cellw];
if (cell==nil)
{
cell=[[[NSBundle mainBundle]loadNibNamed:@"mySpaceCell" owner:nil options:nil] lastObject];
}
NSDictionary* dict=self.plistArray[indexPath.row];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
cell.icon.image=[UIImage imageNamed:dict[@"icon"]];
cell.visitorFriendIcon.image=[UIImage imageNamed:dict[@"visitorFriendIcon"]];
cell.visitorLabel.text=dict[@"visitorLabel"];
cell.friendName.text=dict[@"friendName"];
return cell;
}
else if (indexPath.section==1){
NSString* celle=@"cell";
LHZoneCell* cell=[tableView dequeueReusableCellWithIdentifier:celle];
if (cell==nil)
{
cell=[[[NSBundle mainBundle]loadNibNamed:@"LHZoneCell" owner:nil options:nil] lastObject];
}
NSDictionary* dict=self.plistDataArray[indexPath.row];
cell.userIcon.image=[UIImage imageNamed:dict[@"userIcon"]];
cell.usernickName.text=dict[@"userName"];
cell.userPubulishTime.text=dict[@"userPubulishTime"];
cell.userContentLabel.text=dict[@"userContentlabel"];
cell.userbrowseLabel.text=dict[@"userbrowseLabel"];
cell.userPhoneSource.text=dict[@"userPhoneSource"];
cell.userAppreciateNumbers.text=dict[@"userAppreciateNumbers"];
cell.userContentImage.image=[UIImage imageNamed:dict[@"userContentImage"]];
return cell;
}
NSString* cellID=@"cell";
gameCell* cell=[tableView dequeueReusableCellWithIdentifier:cellID];
if (cell==nil) {
cell=[[[NSBundle mainBundle]loadNibNamed:@"gameCell" owner:nil options:nil] lastObject];
}
NSDictionary* dict=self.playArray[indexPath.row];
cell.gameIcon.image=[UIImage imageNamed:dict[@"image"]];
cell.gameCount.text=dict[@"peopleCount"];
cell.gameTitle.text=dict[@"title"];
cell.gameType.text=dict[@"type"];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//第三组的高度
if (indexPath.section == 2) {
return 92;
}
else if (indexPath.section==1){
return 320;
}
else{
//第一组的高度
return 50;
}
}
@end
转载于:https://my.oschina.net/iOSliuhui/blog/518317
仿QQ空间用一个tableview显示多种自定义cell相关推荐
- 仿QQ空间说说TextView内容显示、收起
这几天做项目遇到需要像QQ空间发表说说内容,当内容超过指定的行数后,后面的内容就不显示.而是显示一个"显示全文"按钮,点击时候才展开所有内容.此时变成"收起"按 ...
- iOS仿QQ空间时间显示
最近项目有类似QQ空间展示动态的UI,模仿了QQ空间的时间显示,在此记录,以备查阅. 这是QQ空间的ui: 时间显示为: 1.今天-->今天 xx:xx(今天 15:39) 2.昨天--&g ...
- 【Android UI设计与开发】第09期:底部菜单栏(四)Fragment+PopupWindow仿QQ空间最新版底部菜单栏
转载请注明出处:http://blog.csdn.net/yangyu20121224/article/details/9023451 在今天的这篇文章当中,我依然会以实战加理论结合 ...
- php 朋友圈留言,php实例-PHP仿qq空间或朋友圈发布动态、评论动态、回复评论、删除动态或评论的功能(上)...
我们大部分人都发过动态,想必都知道发动态.回复评论.删除动态的整个过程,那么这个功能是如何实现的呢?下面小编给大家带来了实例代码,对PHP仿qq空间或朋友圈发布动态.评论动态.回复评论.删除动态或评论 ...
- android弹窗使用总结,高仿QQ空间操作弹窗
android弹窗一共有两种方式,一种是dialog及其子类,另一种是popupwindow:Dialog及其子类尤其AlertDialog是最常用的,也是最自由的一种. **Popupwindow与 ...
- 高仿QQ空间项目实战开发(带服务器端程序)
大家好,今天我在这里分享一个小程序.高仿QQ空间的APP,这里给大家分享一个安卓APP和PHP写的服务器程序.想提高安卓开发能力或安卓和后台服务器一起做的初学者值得一看,老鸟跳过. 接下来我们看看效果 ...
- php mysql仿微信朋友圈评论表设计_PHP仿qq空间或朋友圈发布动态、评论动态、回复评论、删除动态或评论的功能(上)...
我们大部分人都发过动态,想必都知道发动态.回复评论.删除动态的整个过程,那么作为初学者,要模仿这些功能有点复杂的,最起码表的关系得弄清楚~~ 先把思路理一下: (1)用户登录,用session读取当前 ...
- android写qq动态界面,Android_Android仿QQ空间主页面的实现,今天模仿安卓QQ空间,效果如 - phpStudy...
Android仿QQ空间主页面的实现 今天模仿安卓QQ空间,效果如下: 打开程序的启动画面和导航页面我就不做了,大家可以模仿微信的那个做一下,很简单.这次主要做一下主页面的实现,下面是主页面的布局: ...
- html5仿qq空间,JS实现的仿QQ空间图片弹出效果代码
本文实例讲述了JS实现的仿QQ空间图片弹出效果代码.分享给大家供大家参考,具体如下: function imageShow(which_click) { var image_path = which_ ...
最新文章
- vscode插件可以直接复制到_一款可以让代码“跳舞”的 VS Code 插件:Power Mode
- Betty's Sales team BP SQL
- ant design vue input change_vue中关于$emit用法的笔记
- stm32f429vref怎么接_STM32如何通过内部VREF得到实际的VDDA值
- 腾讯微博正式关闭:目前无法登陆 用户可申请个人内容备份
- CTA策略07_MultiTimeframeStrategy
- 案例-三角形(CSS3)
- C++ 多线程系统编程精要
- android 5.0 lg g2,升级到Android 5.0 的LG G2怎样Root?
- Iometer存储测试工具参数说明-3 results display
- 测试老鸟常用的自动化测试工具有哪些?
- 使用开源项目DCRM搭建Cydia源服务器
- Linux-网络管理
- 工业镜头景深计算及工业镜头技术分析
- mysql表字段一定要写英文吗_关于数据库列名是否必须是英文的?
- rtsp 华为_【V哥漫画安防】华为摄像机RTSP流常见问题解答
- 酷炫机器人简笔画图片_卡通机器人简笔画图片
- java货物进销管理系统【电竞杜小帅】
- 整个领域没了!学术界有史以来最大的造假丑闻曝光!
- 用HTML5+CSS实现3d动画立方体