ios初识UITableView及简单用法二(模型数据)

//
// ViewController.m
// ZQRTableViewTest
//
// Created by zzqqrr on 17/8/24.
// Copyright (c) 2017年 zzqqrr. All rights reserved.
// #import "ViewController.h"
#import "ZQRCarGroup.h" @interface ViewController () <UITableViewDataSource>
@property (weak,nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong) NSArray *carGroups;
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
//设置数据源
self.tableView.dataSource=self;
} - (NSArray *)carGroups
{
if(_carGroups==nil){
ZQRCarGroup *model1=[[ZQRCarGroup alloc] init];
model1.title=@"哈哈";
model1.desc=@"呵呵";
model1.cars=@[@"第一组第一行"]; ZQRCarGroup *model2=[[ZQRCarGroup alloc] init];
model2.title=@"哈哈";
model2.desc=@"呵呵";
model2.cars=@[@"第二组第一行",@"第二组第二行"]; ZQRCarGroup *model3=[[ZQRCarGroup alloc] init];
model3.title=@"哈哈";
model3.desc=@"呵呵";
model3.cars=@[@"第三组第一行",@"第三组第二行",@"第三组第三行"];
_carGroups=@[model1,model2,model3];
}
return _carGroups;
} /** 设置多少组组 */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.carGroups.count;
}
/** 指定组中的行 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
ZQRCarGroup *group=self.carGroups[section];
return group.cars.count;
} /** 每一组显示的内容 */
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
ZQRCarGroup *group=self.carGroups[indexPath.section];
NSString *strCar=group.cars[indexPath.row];
cell.textLabel.text=strCar;
return cell;
}
/** 头部文字 */
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
ZQRCarGroup *model=self.carGroups[section];
return model.title;
}
/** 尾部文字 */
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
ZQRCarGroup *model=self.carGroups[section];
return model.desc;
}
@end
模型
//
// ZQRCarGroup.h
//
//
// Created by zzqqrr on 17/8/25.
//
// #import <Foundation/Foundation.h> @interface ZQRCarGroup : NSObject
/**
*头部标题
*/
@property (nonatomic,copy) NSString *title;
/**
*尾部的描述
*/
@property (nonatomic,copy) NSString *desc;
/**
*所有的信息列表
*/
@property (nonatomic,strong) NSArray *cars;
@end
//
// ZQRCarGroup.m
//
//
// Created by zzqqrr on 17/8/25.
//
// #import "ZQRCarGroup.h" @interface ZQRCarGroup() @end @implementation ZQRCarGroup @end
ios初识UITableView及简单用法二(模型数据)的更多相关文章
- ios初识UITableView及简单用法一
// // ViewController.m // ZQRTableViewTest // // Created by zzqqrr on 17/8/24. // Copyright (c) 2017 ...
- IOS SWIFT UITableView 实现简单微博列表
// // Weibo.swift // UITableViewCellExample // // Created by XUYAN on 15/8/15. // Copyright (c) 2015 ...
- AJ学IOS 之微博项目实战(8)用AFNetworking和SDWebImage简单加载微博数据
AJ分享,必须精品 一:效果 没有图文混排,也没有复杂的UI,仅仅是简单的显示出微博数据,主要介绍AFNetworking和SDWebImage的简单用法 二:加载数据AFNetworking AFN ...
- iOS开发UI篇—Quartz2D简单使用(二)
iOS开发UI篇—Quartz2D简单使用(二) 一.画文字 代码: // // YYtextview.m // 04-写文字 // // Created by 孔医己 on 14-6-10. // ...
- iOS block-base 动画简单用法+关键帧动画设置线性变化速度的问题
本文转载至 http://www.tuicool.com/articles/aANBF3m 时间 2014-12-07 20:13:37 segmentfault-博客原文 http://segm ...
- iOS知识点、面试题 之二
最近面试,与大家分享一下,分三文给大家: 当然Xcode新版本区别,以及iOS新特性 Xcode8 和iOS 10 在之前文章有发过,感兴趣的可以查阅: http://www.cnblogs.com/ ...
- iOS基础 - UITableView的数据源(dataSource)和代理(delegate)
UITableView的数据源(dataSource)和代理(delegate) UITableView需要一个数据源(dataSource)来显示数据,UITableView会向数据源查询一共有多少 ...
- iOS开发——UI进阶篇(一)UITableView,索引条,汽车数据展示案例
一.什么是UITableView 在iOS中,要实现展示列表数据,最常用的做法就是使用UITableViewUITableView继承自UIScrollView,因此支持垂直滚动,而且性能极佳 UIT ...
- iOS开发UI篇—简单介绍静态单元格的使用
iOS开发UI篇—简单介绍静态单元格的使用 一.实现效果与说明 说明:观察上面的展示效果,可以发现整个界面是由一个tableview来展示的,上面的数据都是固定的,且几乎不会改变. 要完成上面的效果, ...
随机推荐
- P2469 [SDOI2010]星际竞速
在何Au的讲解下终于搞明白了这个以前的坑. 首先考虑最小路径覆盖. 这个题意又要求我们求出的最大流为n-1(这样才能保证路径为1条) 考虑高速航行模式的图怎么建,只需要保证最大流的同时费用最小即可,显 ...
- Android BottomNavigationBar底部导航控制器的使用(包含默认postion的设置)
转载请标明出处:http://blog.csdn.net/u010046908/article/details/50962081本文出自:[李东的博客] 最近Google在自己推出的Material ...
- LINQ 中常用函数使用: Take TakeWhile Skip SkipWhile Reverse Distinct
1,Take 方法 Take方法用于从一个序列的开头返回指定数量的元素. string[] names = { "郭靖", "李莫愁", "欧阳晓晓& ...
- 几种常见的开源软件许可协议(GPL, LGPL, Apache License, BSD)
GPL GPL授予程序接受人以下权利,或称“自由”: * 以任何目的运行此程序的自由 * 以学习程序工作机理为目的,对程序进行修改的自由(能得到源代码是前提) * 再发行复制件的自由 * 改进此程序, ...
- 一个典型的多表参与连接的复杂SQL调优(SQL TUNING)引发的思考
今天在看崔华老师所著SQL优化一书时,看到他解决SQL性能问题的一个案例,崔华老师成功定位问题并进行了解决.这里,在崔华老师分析定位的基础上,做进一步分析和推理,以便大家一起研究探讨,下面简述该案例场 ...
- python http 请求 响应 post表单提交
1. 查看请求 响应情况 print(response.text) print(response.headers) print(response.request.body) print(respons ...
- commonJS 和 ES6 模块化的不同
commonjs 导出 module.exports={ add:function(){ console.log('add测试') } } 导入 var add=require('./add.js') ...
- lda topic number
Hi Vikas -- the optimum number of topics (K in LDA) is dependent on a at least two factors: Firstly, ...
- 逆袭之旅DAY13.东软实训.Oracle.简单的查询语句.限制.排序
2018-07-09 21:34:00 一.简单查询: .查询数据表的所有列: SELECT * FROM 表名; SELECT 列名,列名.... FROM 表名; .起别名: SELECT 列名 ...
- shell 键盘输入
命令:read 从键盘读入数据,赋值变量 [root@ssgao shell]# cat b.sh #!bin/bash read a b c echo "a is : ${a}" ...