一、梗概:

  1、自定义:headerView,footerVie,Cell等

  2、双模型(遵循单一原则,类或模型实现的功能尽量单一)

  3、计算文本的方法(针对不同文本内容而设置的宽高等)

  4、设置footerView和headerView的注意事项(能修改的值可以是xmargin和高度,有些是不能修改的方法 ,采取方式:设置一个tempView,实际的操作都在tempView中进行)

  5、UIActivityIndicatorView(转动菊花)startAnimating/stopAnimating

  6、注意alpha=0和clean color 的区别(alpha=0设置,其子控件也会相应的看不见,但是cleancolor的话,只能让其颜色变为透明,子控件依旧可见)

  7、延迟的方法(performSelector/dispatch_after(GCD :grand central dispatch))

二、自定义headerView(ScrollView和pageControl)

创建一个bannerview 继承自UIView

@property (nonatomic ,strong) NSArray* imageArray;//数据定义在viewcontroller中,功能要分开

a、设置scrollview

b、设置pageControl

1、设置ScrollView属性(滚动的范围和图片的大小和数量有关,暂时不设置contentSize)

scrollview.showsHorizontalScrollIndicator =NO;

scrollview.pagingEnabled=YES;

将scrollview实例化

self.scrollview=scrollview;

2、设置pagecontrol属性(总的page数和数组的图片数量有关,暂不设置 numberOfPages)

pagecontrol.currentPage =0;

pagecontrol.pageIndicatorTintColor =[UIColor grayColor];

pagecontrol.currentPageIndicatorTintColor=[UIColor redColor];

将pagecontrol实例化

self.pagecontrol=pagecontrol;

3、设置pagecontrol的总页数和scrollView的滚动范围

scrollview.contentSize =CGSizeMake(count*self.bounds.size.width,0);

pagecontrol.numberOfPages=ImageArray.count;

4、设置根据scrollview的滚动让pagecontrol的currentpage跟随着变化(contentOffset scrollviewDidEndDecelerating)

-(void) scrollviewDidEndDecelerating:(UIScrollView*)scrollview

{

_pagecontrol.currentPage = _scrollview.contentOffset.x/(self.bounds.size.width);

}

5、如何在viewcontroller的tableview调用该bannerview作为其headerview

#import "BannerView.h"

BannerView *bannerview=[[BannerView alloc]initWithFrame:CGrectMake(0,0,[UIScreen mainScreen].bounds.size.width,200)];

BannerView.imageArray =@[@"",@"",@"",@""];//传入图片数据

tableview.tableHeaderView =bannerview;

三、自定义footerView(两个方法,一、直接手动添加footerview 二、xib)

三(1)手动添加footerView

UIView *tempView =[UIView alloc]initWithFrame:CGRectMake(0,0,self.view.bounds.size.width,120)];

UIButton *footerbtn =[[UIButton alloc]initWithFrame:CGRectMake(10,10,self.view.bounds.size.width-20,65)];

[footerbtn setTitle :@"点击加载更多" fotState :UIControlStateNormal];

//如果要实现footerbtn的方法,用addTarger

footerbtn.BackgroundColor=[UIColor orangeColor];

[tempView addSubview:footerbtn];

tableview.tableFooterView =tempView;

三(2)通过xib设置footerview

1、创建名为FooterView的Xib文件 并关联属性

2、在viewcontroller中的tableview中加载footerview(NSBundle mainBundle loadNibNamed)

#import "FooterView.h"

FooterView *footerView =[[[NSBundle mainBundle]loadNibNamed:@"FooterView" owner:nil options:nil]lastObect];

tableview.tableFooterView =footerview(此时,不需要定义临时视图就可以直接添加了)

3、实现footerview中的加载按钮,实现(按钮文字变换,菊花转动,插入新的数据)

1)在xib中加入一个view其中包含UIActivityIndicatorView和label:正在加载中

并把这个view 的alpha设置为0

注意,当把view的背景色设置为cleanColor

虽然view不见了,可是label“正在加载中”和菊花仍在

而alpha=0则view及view里面所有子控件都看不见

1)定义btnclick 的方法

-(IBAction)loadButton:(id)sender{

}

-(void)showLoadViewWith:(BOOL)isShow

{

_moreView.alpha=0;

if(isShow)

{[_activiteView startAnimating];}

else{[_activiteView stopAnimating];}}

2)当footerview中的按钮被点击的时候,viewController中应该为其传入数据(此处可以联想到使用代理)

2.1)怎么实现代理??

a、@class FooterView;

b、@protocol FooterViewDelegate<NSObject>

c、定义代理方法

-(void )footerview:(FooterView *)footerView;

d、创建代理属性(weak注意用weak,用strong的话,双方都是强引用,造成循环引用而不被释放)

@property (nonatomic,weak)if<FooterViewDelegate>delegate;

e、在执行方法的button事件中,触发代理方法通知获取数据(self.delegate respondsToSelector:@selector(footerView:)])

-(IBAction)loadButton:(id)sender{

if([self.delegate respondsToSelector:@selector(footerView:)]){

[self.delegate footerView:self];}}

f、在viewcontroller中实现代理方法

  <FooterViewDelegate>

-(void)footerView:(FooterView*)footerView

{

[footerView showLoadViewWith:YES];

//添加数据的时候,实现延迟效果有两个方法

方法一、[self(performSelector:@selector(loadMoreData:)Withbject:nil afterDelay:2)];

方法二、dispatch_after(dispath_time(DISPATCH_TIME_NOW,(int64_t)(2*

NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

[footerView showLoadViewWith:NO];

//添加的数据

       GroupModel *model =[[GroupModel alloc]init];

   model.title=@"江边一枝花";

 model.icon=@"2c97690e72365e38e3e2a95b934b8dd2";

[self.dataArray addObject:model];

//刷新数据

#warning 当我选择单个刷新的时候,会报错,只能选择全部刷新

NSIndexPath *indexPath =[NSIndexPath indexPathForRow:self.dataArray.count -1 inSection:0];

/* [_tableview reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];

*/

[_tableview reloadData];

//滚动到最后一行

[_tableview scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:true];

});

Objective-c——UI基础开发第七天(自定义UITableView)的更多相关文章

  1. Solon 开发,七、自定义注解开发汇总

    Solon 开发 一.注入或手动获取配置 二.注入或手动获取Bean 三.构建一个Bean的三种方式 四.Bean 扫描的三种方式 五.切面与环绕拦截 六.提取Bean的函数进行定制开发 七.自定义注 ...

  2. Objective-c——UI基础开发第十天(自动布局)

    一.autoresizing 的使用(了解) 只能参照父控件 1.实现横竖屏幕切换,不能把控件的frame血丝,需要进行屏幕适配 2.需要参照父控件 use auto layout禁用 才会出现aut ...

  3. Objective-c——UI基础开发第九天(QQ好友列表)

    一.知识点: 1.双模型的嵌套使用 2.Button的对齐方式 3.优化UITableView的加载 4.layoutSubview的使用 5.cell的折叠代理 二.双模型的嵌套定义: 注意是将se ...

  4. Objective-c——UI基础开发第八天(QQ聊天界面)

    一.知识点: QQ聊天界面 双模型的使用(dataModel和frameModel) UITextField的使用 通知的使用 拉伸图片的两种方法(slicing/image对象的resizeable ...

  5. Objective-c——UI基础开发第十二天(相册展示)

    一.知识点 模仿新特性 UICollectionViewFlowLayout自定义布局 相册 瀑布流(淘宝购物之类的 二.复习 a.UICollectionView 和 tableview共享一套AP ...

  6. Objective-c——UI基础开发第十一天(UICollectionView)

    一.知识点 1.UICollectionView的dataSource .delegate 2.UICollectionView多组数据和单组数据的展示 3.UICollectionView.UICo ...

  7. Objective-c——UI基础开发第六天(UITableView)

    一.UITableView的简单使用 显示要素: 1.显示多少给区组 2.显示多少行数据 3.每行显示什么内容 代理不会提醒你有什么方法没调用,但是UITableViewDataSource会 1)用 ...

  8. iOS学习——UI基础UIButton(七)

    前面写了UIWindow.UIViewController,那些都是一些框架,框架需要填充上具体的view才能组成我们的应用,移动应用开发中UI占了很大一部分,最基础的UI实现是使用系统提供的各种控件 ...

  9. 浅谈Excel开发:七 Excel 自定义任务窗体

    前面花了三篇文章讲解了Excel中的UDF函数,RTD函数和异步UDF函数,这些都是Excel开发中的重中之重.本文现在开始接着第二篇文章的菜单系统开始讲解Excel中可供开发的界面元素,本文要讲解的 ...

随机推荐

  1. Windows8 10设置程序为 系统默认浏览器

    从win8 开始,MS修改了文件和协议的关联方式,普通的注册表修改是无效的. 必须使用组策略(group policy )对象GP才行. http://blogs.technet.com/b/mrml ...

  2. 有关嵌入式linux的注意点总结

    知识收集和个人学习过程遇到的问题. 仅供参考. 1.sudo apt-get update 一直无法更新 一,查看网络是否连接上 有几种网络连接方式.常用的两种有网桥网络(Bridged)和网络地址翻 ...

  3. 原子操作 Interlocked系列函数

    上一篇<多线程第一次亲密接触 CreateThread与_beginthreadex本质区别>中讲到一个多线程报数功能.为了描述方便和代码简洁起见,我们可以只输出最后的报数结果来观察程序是 ...

  4. D.T SOFTWARE (1) 软件架构直播答疑课程

    今晚的d.t课程 1项目需求 PPTP服务搭建完成PPTP服务器的搭建,用户重新拨号获得新IP后,要求拔PPTP VPN成功时,也获取到新的公网IP,而且能通过代理上网.VNC服务安装用户可以通过VN ...

  5. $.noop()和$.map()函数

    最近在项目中发现$.noop()函数,因以前没使用过故查询下,现整理如下: jQuery.noop()函数是一个空函数,它什么也不做. 当某些时候你需要传入函数参数,而且希望它什么也不做的时候,你可以 ...

  6. 12-26 tableView的学习心得

    一:基础部分 UITableView的两种样式: 注意是只读的 1.UITableViewStytlePlain(不分组的) n 2.UITableViewStyleGrouped(分组的) 二:如何 ...

  7. GSM Hacking:如何对GSM/GPRS网络测试进行测试

    写在前面 这里需要介绍的是GSM / GPRS网络测试的一些方法,随着现在硬件设备连网现象的普遍存在,例如智能电表.自动变速箱控制单元(TCU).POS机.报警系统等.这些设备通常需要与网络连接,GS ...

  8. ios上 更改 状态栏(UIStatusBar)

    摘要 ios上 更改状态栏(UIStatusBar)的颜色 ios UIStatusBar statusBar 状态栏 更改状态栏颜色 目录[-] IOS上 关于状态栏的相关设置(UIStatusBa ...

  9. 初次使用百度地图API

    因为项目需要,不得不使用百度地图的API,以前从未了解过API,这不是唬人,真的,所以对百度地图API充满了恐惧,但是到后面,已经麻木了.期间遇到过很多错误,每一个都弄得头大,借博客的名义把平时遇到的 ...

  10. JAVA嵌套循环

    Java语言中的各种循环.选择.中断语句和C/C++一般无二. 选择结构 循环结构 中断(跳转) if for return if else while break if elseif do whil ...