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来展示的,上面的数据都是固定的,且几乎不会改变. 要完成上面的效果, ...
随机推荐
- tcpcopy真实流量压测工具
https://quentinxxz.iteye.com/blog/2249799 http://blog.chinaunix.net/uid-25057421-id-5576741.html htt ...
- 关于react16.4——上下文Context
首先我们来聊一聊(上下文)Context. 上下文(Context) 提供了一种通过组件树传递数据的方法,无需在每个级别手动传递 props 属性. 在典型的 React 应用程序中,数据通过 pro ...
- 关于Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op.的解决方案
Warning: setState(...): Can only update a mounted or mounting component. This usually means you call ...
- Mybatis 查询tinyint(1)的数据库字段时会自动转换成boolean类型
解决方案:将字段的tinyint(1)变成tinyint(2)
- Python序列化-pickle和json模块
Python的“file-like object“就是一种鸭子类型.对真正的文件对象,它有一个read()方法,返回其内容.但是,许多对象,只要有read()方法,都被视为“file-like obj ...
- PHPCMS V9完全开发介绍
PHPCMS V9 文件目录结构: 根目录 | – api 接口文件目录 | – caches 缓存文件目录 | – configs 系统配置文件目录 | – caches_* 系统缓存目录 | – ...
- ActiveMQ broker和客户端之间的确认
生产者发送消息:producer ---------> broker broker返回确认:broker ---------> producer 生产者发送同步消息,broker会返回Re ...
- Microsoft Windows远程桌面协议中间人攻击漏洞(CVE-2005-1794)漏洞解决方案(Windows server2003)
1.启动“终端服务配置” 2.选择“连接”,看到“RDP-Tcp”,在其上右键,选择“属性” 3.“常规”选项卡,将加密级别修改为“符合FIPS标准”,点击应用 应用即可,实验发现并不需要重启服务或操 ...
- python(5)之集合
集合是一个无序的,不重复的数据组合,它的主要作用如下: 1.去重,把一个列表变为集合就自动去重了 2.关系测试,测试两组数据之间的交集.并集.差集等 常用操作如下: #集合的操作 list_1={1, ...
- Oracle 如何循环查询结果集,进行新增或修改
Oracle的PL/SQL中怎样循环查询的结果集,然后根据查询结果进行判断,是新增或修改操作 loop循环例子 for item in (select a,b,c from table_a where ...