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来展示的,上面的数据都是固定的,且几乎不会改变. 要完成上面的效果, ...
随机推荐
- getopt实现传参自动识别
test.py #!/usr/bin/env python # -*- coding: utf-8 -*- import getopt import sys #-h-f-v为了下面的识别 opts,a ...
- 了解一下express中间件的意思以及next()
app.use()就是通常所说的使用中间件 一个请求发送到服务器后,它的生命周期是 先收到request(请求),然后服务端处理,处理完了以后发送response(响应)回去,而这个服务端处理的过程就 ...
- HTML标签(二)
一.字体标签 字体标签包含:h1~h6.<font>.<u>.<b>.<strong><em>.<sup>.<sub> ...
- 将本地分支push到远程分支
git push origin [localbranch]:[remotebranch]
- java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0). at co ...
- 【转】vs IIS破除文件上传限制最全版
今天在测试一下上传文件的时候发现iis和配置存在上传文件大小限制(IIS默认大小30M,最大运行为2g:2147483647),百度了一部分资料有些发布到IIS好使,但是在VS调试中不好使.于是自己不 ...
- js重写系统的弹框
//调用系统的弹框,不显示地址 window.alert = function(name){ var iframe = document.createElement("IFRAME& ...
- Java集合list,map,set区别及遍历
1.1 List.Set.Map基本区别 1.List,Set都是继承Collection接口,Map不是. 2.List:LinkedList.ArrayList.Vector Set :HashS ...
- 补交第二周作业:学习ka li
在老师给的虚拟机上安装,试了n次都没有安装成功,百度上的说法也是众说纷纭. 之后重新安装了另一个版本的虚拟机,按照教程成功装上了ka li. 一. 安装VMtools:是为了方便宿主机与虚拟机间的文件 ...
- Java中的标签
@SuppressWarnings 简介:java.lang.SuppressWarnings是J2SE 5.0中标准的Annotation之一.可以标注在类.字段.方法.参数.构造方法,以及局部变量 ...