Objective-c——UI基础开发第九天(QQ好友列表)
一、知识点:
1、双模型的嵌套使用
2、Button的对齐方式
3、优化UITableView的加载
4、layoutSubview的使用
5、cell的折叠代理
二、双模型的嵌套定义:
注意是将self.friends 尚未字典转模型进行的操作
二、cell的重用定义方式
方法一
QQCell *cell =[tableView dequeueReusableCellWithIdentifier:identifier];
/**
但是这种方法,如果不是在xib中定义了identifier是不会被重用的,使用方法二进行重用
if(cell==nil)
{
cell=[[NSBundle mainBundle]loadNibNamed:@"QQCell" owner:nil options:nil].lastObject;
}
*/
方法二
/**
到tableview注册一个重用的cell
NibName:xib的文件名
bundle:传空就是默认当前的bundle
没有使用xib registerClass 假设没有和xib进行关联
*/
UINib *nib=[UINib nibWithNibName:@"QQCell" bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:@"QQCell"];
方法二的不需要再判断cell是否为空 就可以在cellforRowAtIndexPath 在做cell是否为nil的判断就可以省略掉
总结:
使用类注册
self.tableview registerClass :forCellReuseIdentifier:
使用xib注册
UINib *nib =[UINib nibWithNibName :@“QQCell” bundle:nil];
[self.tableview registerNib:nib forCellReuseIdentifier:@“QQCell”];
三、button的布局
/**
重点怎么设置button 中text 和 image 都是左对齐,且image和text保持一定距离
1、设置contentHorizontalAlignment(UIControlContentHorizontalAlignmentCenter/left/Right/Fill)
2、设置text 和 image 的内边距(imageEdgeInsets/titleEdgeInsets)
*/
headerButton.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
//设置图片或文本的内边距 分别采用 imageEdgeInsets/titleEdgeInsets UIEdgeInsetsMake
headerButton.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
headerButton.titleEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
4.2)图片的旋转,问题:图片旋转之后可能会出现拉伸状况:
/**
为了在旋转之后保持原有的形状(contentMode)
UIViewContentModeScaleToFill 拉伸填充
UIViewContentModeScaleAspectFit 自适应
UIViewContentModeScaleAspectFill 自适应填充
UIViewContentModeCenter,保持原有的尺寸
*/
headerButton.imageView.contentMode = UIViewContentModeCenter;
#pragma mark 发现超出父view 的边界部分将会被切掉 修改属性 clipsToBounds
headerButton.imageView.clipsToBounds =NO;
四、tableview 的重用 (类似cell的重用)
/**
1、定义一个重用标识符
2、到缓存池中去找
3、判断是否为空
4、对headerview进行赋值并返回
*/
static NSString *headerIdentifier =@"HeaderView";
HeaderView *headerView =[tableView dequeueReusableHeaderFooterViewWithIdentifier:headerIdentifier];
if(nil==headerView)
{
headerView=[[HeaderView alloc]initWithReuseIdentifier:headerIdentifier];
}
注意再HeaderView的类中 //外部调用的是哪个实例化方法,那么就重写哪个方法
所以使用:
if(self =[super initWithReuseIdentifier:reuseIdentifier])
五、在HeaderView中,加载的子view不能显示的原因:(LayoutSubview)
view无法显示的原因有:
1、颜色与父view相同
2、没有添加到父view
3、没有设置Frame
4、透明度
5、被别的控件遮盖
6、hidden=yes
7、检查父view的上述情况
注意:使用subview就相当于对控件进行一个强引用
//layer:布局 当view 的frame发生改变的时候就会调用
/**
如果在实例化的时候没有取到当前的frame
或者当当前的frame发生变化
或者当钱frame的bounds全部为0时
这个方法对内部的子view(frame),对控件进行设置
*/
-(void)layoutSubviews
{#warning 一定要调用父类的方法 因为这个是针对frame发生改变时调用的,所以不应该在这里做添加 只做frame 的设置,其它东西别动
[super layoutSubviews];
六、cell的折叠代理添加协议
1、设置代理属性
@class HeaderView;
@protocol HeaderViewDelegate<NSObject>
-(void)headerView:(HeaderView *) headerView didClickButton :(UIButton *)button;
@property (nonatomic,weak) id<HeaderViewDelegate> delegate;
2、通知代理
-(void)didClickButton:(UIButton *)button
{if([self.delegate responsToSelector:@selector(headerView:didClickButton:)])
{[self.delegate headerView:self didClickButton:button];}}
3、在viewcontroller中 遵守协议实现代理方法
headerView.delegate=self;
-(void)headerView:(HeaderView*)headerView didClickButton:(UIButton*)button{
}
提示:
numberofrowsInSection返回0时 将不执行cellForRowAtIndexPath
七、tip如何在代理中取出模型对应的section 并对model中的变量进行修改(tag)
在tableview的 viewForHeaderInSection重用方法中:
//获取哪一组
headerView.tag=section;
在协议方法中获取section
//1、 获取section的数值
NSInteger section = headerView.tag;
NSInteger section = headerView.tag;
//2、获取groupModel
GroupsModel *groupModel = self.dataArray[section];
//3、对groupModel中的isExplain变量进行修改
groupModel.explain =!groupModel.isExplain;
//4、刷新表格,为什么explain明明设置为yes了还是没用,因为tableview已经调用过numberofrowInsection方法,要想重新调用,需要使用reload刷新
//[_tableview reloadData];
NSIndexSet *indexSet =[NSIndexSet indexSetWithIndex:section];
[_tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
#pragma mark 这里有一个问题,为什么三角形图像会点击一次加一次 就会出现类似瞬间变回原样的状态? 与reload的刷新有关,刷新将会让tableview的所有代码又重新执行一遍
Objective-c——UI基础开发第九天(QQ好友列表)的更多相关文章
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)
iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一) 一.项目结构和plist文件 二.实现代码 1.说明: 主控制器直接继承UITableViewController // ...
- [iOS基础控件 - 6.9.3] QQ好友列表Demo TableView
A.需求 1.使用plist数据,展示类似QQ好友列表的分组.组内成员显示缩进功能 2.组名使用Header,展示箭头图标.组名.组内人数和上线人数 3.点击组名,伸展.缩回好友组 code so ...
- Windows UIA自动化测试框架学习--获取qq好友列表
前段时间应公司要求开发一款针对现有WPF程序的自动化测试工具,在网上查资料找了一段时间,发现用来做自动化测试的框架还是比较多的,比如python的两个模块pywinauto和uiautomation, ...
- (二十七)QQ好友列表的实现
QQ好友列表通过plist读取,plist的结构为一组字典,每个字典内有本组的信息和另外一组字典代表好友. 要读取plist,选择合适的数据结构,例如NSArray,然后调用initWithConte ...
- android 实现QQ好友列表
在某些Android开发群里,看到有些新手问怎么实现QQ好友列表,其实网上一搜挺多的.接触Android,也才一年的时间,大部分时间花在工作上(解bug...),界面上开发很少参与.自己维护的系统应用 ...
- 仿QQ好友列表界面的实现
TableView有2种style:UITableViewStylePlain 和 UITableViewStyleGrouped. 但是QQ好友列表的tableView给人的感觉似乎是2个style ...
- ExpandableListView仿QQ好友列表
本例中,对ExpandableListView中的数据进行了封装,分为两个JavaBean,一个为Group类表示组信息,一个Child类表示该组下子列表信息: Group: public class ...
- 基于Qt的相似QQ好友列表抽屉效果的实现
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/shuideyidi/article/details/30619167 前段时间在忙毕业设计, ...
- swift 实现QQ好友列表功能
最近项目中有类似QQ好友列表功能,整理了一下,话不多说,直接上代码 import UIKit class QQFriend: NSObject { var name: String? var intr ...
- OS开发UI篇—使用UItableview完成一个简单的QQ好友列表
本文转自:http://www.cnblogs.com/wendingding/p/3763330.html 一.项目结构和plist文件 二.实现代码 1.说明: 主控制器直接继承UITableVi ...
随机推荐
- bzoj 3529 数表 莫比乌斯反演+树状数组
题目大意: 有一张N×m的数表,其第i行第j列(1 < =i < =礼,1 < =j < =m)的数值为能同时整除i和j的所有自然数之和.给定a,计算数表中不大于a的数之和. ...
- 五大要求让BPM与企业对接
BPM(即业务流程管理)在中国已经有多年的发展历史,但人们经常提到的还是企业对流程的迫切需要,鲜有人讨论什么样的企业才能实施BPM,或者换句话说BPM的本身对企业有什么要求.不是所有的工作都适合BPM ...
- javaweb之Cookie篇
Cookie是在浏览器访问某个Web资源时,由Web服务器在Http响应消息头中通过Set-Cookie字段发送给浏览器的一组数据. 一个Cookie只能表示一个信息对,这个信息对有一个信息名(Nam ...
- Cisco IOS Software Activation Command Reference
clear license agent : to clear license agent statistics counters or connection statistics (in privil ...
- ajax异步文件上传,iframe方式
不是我写的,我看了他的,思路很明确: 实现思路: 在js脚本中动态创建form,动态创建form中的内容,将文件上传的内容以隐藏域的方式提交过去,然后写好回调等. 感觉思路不难,但是我写不出来,感觉需 ...
- ognl表达式root中取值顺序
不加#,先从栈顶取,如果没有(是没有这个属性而不是这个属性没有值),再往下取. 如果栈顶和非栈顶的对象拥有同一个属性名称,想直接取非栈顶的属性可以在ognl中用#root[i].属性名,可以取到属性的 ...
- STM32下载显示target dll has been cancelled
使用MDK 4.74向STM32下载时出现各种错误,而且时隐时现, Internal command error.Error:Flash download failed. Target DLL has ...
- TCP协议三次握手过程分析【图解,简单清晰】
转自:http://www.cnblogs.com/rootq/articles/1377355.html TCP(Transmission Control Protocol) 传输控制协议 TCP是 ...
- linux 快速安装mysql
yum list | grep mysqlyum install -y mysql-server mysql mysql-devel service mysqld startmysqladmin -u ...
- What is hmux in resin?
When I start the Resin server it says hmux listening to localhost:6802 What is this hmux? Is this a ...