iOS大典之表视图UITableView
2015-10-05 21:44
411 查看
UITableView
表视图用来显示数据列表,
它遵守两个协议:
因为
获取配置数据 UITableViewDelegate
获取行数据 UITableViewDataSource
表视图有两种基本样式:
1: 无格式表 UITableViewStylePlain .
每个分组的标题可以自定义样式, 使用了索引, 又叫索引表
2: 分组表 UITableViewStyleGrouped .
分组间有明显的间距, 一个分组表只有一个分组, 分组表不该使用索引
表视图单元格样式:
UITableViewCellStyleDefault, 不含详细文本
UITableViewCellStyleValue1, 单元两端, 详细在后
UITableViewCellStyleValue2
不显示图标, 详细文本标签在文本标签的左侧
UITableViewCellStyleSubtitle 一上一下, 详细在下
创建后先设置协议
一般会用数组来把数据显示出来
最重要的两个属性, 必不可少
loading
表视图用来显示数据列表,
它遵守两个协议:
因为
获取配置数据 UITableViewDelegate
获取行数据 UITableViewDataSource
表视图有两种基本样式:
1: 无格式表 UITableViewStylePlain .
每个分组的标题可以自定义样式, 使用了索引, 又叫索引表
2: 分组表 UITableViewStyleGrouped .
分组间有明显的间距, 一个分组表只有一个分组, 分组表不该使用索引
表视图单元格样式:
UITableViewCellStyleDefault, 不含详细文本
UITableViewCellStyleValue1, 单元两端, 详细在后
UITableViewCellStyleValue2
不显示图标, 详细文本标签在文本标签的左侧
UITableViewCellStyleSubtitle 一上一下, 详细在下
创建后先设置协议
@interface ViewController ()<UITableViewDataSource, UITabBarDelegate>
一般会用数组来把数据显示出来
@property (copy, nonatomic)NSArray *fuck;
- (void)viewDidLoad { [super viewDidLoad]; self.fuck = @[@"A", @"F", @"C", @"U", @"K"]; UITableView *tableView = (id)[self.view viewWithTag:1]; UIEdgeInsets contentInset = tableView.contentInset; contentInset.top = 20; [tableView setContentInset:contentInset]; }
最重要的两个属性, 必不可少
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.dwarves count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // 声明一个静态字符串 static NSString *FuckIdentifier = @"FuckIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:FuckIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:FuckIdentifier]; // 如果是nil, 就用标识符字符串手动创建个新的表视图单元 } cell.textLabel.text = self.dwarves[indexPath.row]; // 从indexPath的row属性获取当前行, 用表的行号从数组中获得对应的字符串, 然后赋给表单元的textLabel.text属性, 最后将表单元返回 return cell; }
loading
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- .net平台推送ios消息的实现方法
- 探讨Android与iOS,我们将何去何从?
- Android、iOS和Windows Phone中的推送技术详解
- IOS 改变键盘颜色代码
- 举例详解iOS开发过程中的沙盒机制与文件
- Android和IOS的浏览器中检测是否安装某个客户端的方法
- javascript实现阻止iOS APP中的链接打开Safari浏览器
- IOS开发第三方语音-微信语音
- iOS开发之路--微博OAuth授权_取得用户授权的accessToken
- 基于UIControl控件实现ios点赞功能
- iOS开发中实现邮件和短信发送的简单示例