UITableView添加footerView按钮
2016-02-12 23:09
351 查看
UITableView添加自定义的footerView按钮
注:不需要设置footer的尺寸// 设置footerView // 注意:不需要设置footer的尺寸 MJTgFooterView *footer = [MJTgFooterView footerView]; footer.controller = self; self.tableView.tableFooterView = footer;
UITableView添加代码创建的footerView按钮
// 设置tableview尾部显示的控件(tableFooterView的宽度永远是tableView的宽度) // tableFooterView只需要设置高度 UIButton *footerBtn = [UIButton buttonWithType:UIButtonTypeSystem]; footerBtn.frame = CGRectMake(0, 0, 0, 35); footerBtn.backgroundColor = [UIColor orangeColor]; [footerBtn setTitle:@"加载更多团购" forState:UIControlStateNormal]; // 创建nib对象 // UINib *nib = [UINib nibWithNibName:@"MJTgFooterView" bundle:[NSBundle mainBundle]]; // 创建nib对象(也可以传入nil - 解释:凡是参数需要传入[NSBundle mainBundle]的都可以使用nil代替,因为默认的就是mainBundle) UINib *nib = [UINib nibWithNibName:@"MJTgFooterView" bundle:nil]; // 因为在tableFooterView中的控件是不可调位置和宽度的,所以要新建个UIView的xib文件来描述底部控件 // 加载xib/nib文件 UIView *footerView = [[nib instantiateWithOwner:nil options:nil] lastObject]; self.tableView.tableFooterView = footerView;
以上代码的注意点:
1)footerBtn.frame = CGRectMake(0, 0, 0, 35);
//前三个属性不需要设置,只需要设置一个高度,宽度不需要去设置,宽度就是UIViewTable的宽度
2)使用另一种方法来获取xib文件,之前使用[NSBundle mainBundle]来获取的
UINib *nib = [UINib nibWithNibName:@"MJTgFooterView" bundle:[NSBundle mainBundle]]; // 之前使用[NSBundle mainBundle]来获取的 NSBundle *bundle = [NSBundle mainBundle]; NSArray *objs = [bundle loadNibNamed:@"MJTgFooterView" owner:nil options:nil]; UIView *appView = [objs lastObject];
注:也可以传入nil - 解释:凡是参数需要传入[NSBundle mainBundle]的都可以使用nil代替,因为默认的就是mainBundle
UINib *nib = [UINib nibWithNibName:@"MJTgFooterView" bundle:nil];
3)因为在tableFooterView中的控件是不可调位置和宽度的,所以要新建个UIView的xib文件来描述底部控件
UINib *nib = [UINib nibWithNibName:@"MJTgFooterView" bundle:nil]; UIView *footerView = [[nib instantiateWithOwner:nil options:nil] lastObject]; // 之前使用[NSBundle mainBundle]来获取的 NSBundle *bundle = [NSBundle mainBundle]; NSArray *objs = [bundle loadNibNamed:@"MJTgFooterView" owner:nil options:nil]; UIView *appView = [objs lastObject];
相关文章推荐
- hdu 5297 Y sequence
- 不允许使用邮箱名称。 服务器响应为:authentication is required
- HRBUST 1005 Counting Subsequences
- POJ 2785 4 Values whose Sum is 0(折半枚举)
- Android蓝牙技术Bluetooth使用流程(详解)
- poj 3368 Frequent values 线段树 离散化
- Android蓝牙技术Bluetooth初体验
- String ,StringBuilder, StringBuffer
- SWTableViewCell——一个和iOS 7的系统Mail类似,使用起来简单的UITableViewCell子类
- UESTC 250 windy数 (数位DP)
- iOS 【UIKit-转换坐标系(2)】
- NGUI 3.5教程(二)Label 标签 (Hello world)、多行文本
- [JSP] - frequently-used skills
- Key-Value Coding
- iOS 【UIKit-转换坐标系(1)】
- durpal8+Acquia Dev Desktop安装问题处理
- hdu1503Advanced Fruits【最长公共子序列】
- LeetCode 96 Unique Binary Search Trees不同的二叉搜索树的个数
- Building Maintainable Software-java篇之Write Simple Units of Code
- Educational Codeforces Round 7 A. Infinite Sequence 水题