UITableView的基本用法
来源:互联网 发布:淘宝北海家自制护肤品 编辑:程序博客网 时间:2024/05/17 20:28
今天给同学们来讲一下UITableView的基本用法,那么我们今天就讲一个汽车的展示列表我们从最最基本最直观的角度来讲解,适合与新手的学习和进步!接下来的博客分享我会把UITableView我所学的东西我所会掌握的东西全部为同学们讲解~那么废话不多说直接上代码!
//
// ZZViewController.m
// 02- 展示汽车品牌
//
// Created by 周昭 on 16/10/27.
// Copyright © 2016年 HT_Technology. All rights reserved.
//
#import "ZZViewController.h"
@interface ZZViewController()
/**
* 此处我们通过storyboard加载tableView并且设置代理和数据源为该控制器
*/
@property (weak,nonatomic)IBOutletUITableView *tableView;
@end
@implementation ZZViewController
- (void)viewDidLoad
{
[superviewDidLoad];
}
#pragma mark - 这里隐藏状态栏
- (BOOL)prefersStatusBarHidden
{
returnYES;
}
#pragma mark - 数据源方法
/**
* 一共有多少组数据
*/
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// NSLog(@"numberOfSectionsInTableView-一共有多少组数据");
return3;
}
/**
* 第section组有多少行
*/
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// NSLog(@"numberOfRowsInSection-%d", section);
#pragma mark - 那么写到这里只是给那些初级入门的初学者看怎么样最直观最直接去实践一个列表的功能可是如果后期的你数据改变那你这个控制器不是死的很惨吗?你的改动不就很大吗?
if (section ==0) {//德系品牌
return3;
} elseif (section ==1){ //日韩品牌
return4;
} else {//欧系品牌
return2;
}
}
/**
* 每一行显示怎样的内容(cell)
*/
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// NSLog(@"cellForRowAtIndexPath-%d组%d行", indexPath.section, indexPath.row);
UITableViewCell *cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:nil];
if (indexPath.section ==0) {//德系品牌(第0组)
if (indexPath.row ==0) {//第0组的第0行
cell.textLabel.text =@"奥迪";
} elseif (indexPath.row ==1) { //第0组的第1行
cell.textLabel.text =@"宝马";
} elseif (indexPath.row ==2) {
cell.textLabel.text =@"奔驰";
}
#pragma mark - 同上面的解释如果改动了那么你的控制器不会死的很惨而且你改动的代码将会是无数那么现在开始重构并且拓展功能
} elseif (indexPath.section ==1) { //日韩品牌(第1组)
if (indexPath.row ==0) {//第1组的第0行
cell.textLabel.text =@"本田";
} elseif (indexPath.row ==1) { //第1组的第1行
cell.textLabel.text =@"丰田";
} elseif (indexPath.row ==2) {
cell.textLabel.text =@"铃木";
} elseif (indexPath.row ==3) {
cell.textLabel.text =@"三菱";
}
} elseif (indexPath.section ==2) { //欧系品牌(第2组)
if (indexPath.row ==0) {//第2组的第0行
cell.textLabel.text =@"兰博基尼";
} elseif (indexPath.row ==1) { //第2组的第1行
cell.textLabel.text =@"劳斯莱斯";
}
}
return cell;
}
/**
* 第section组显示怎样的头部标题
*/
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section ==0) {
return@"德系品牌";
} elseif (section ==1) {
return@"日韩品牌";
} else {
return@"欧系品牌";
}
}
/**
* 第section组显示怎样的尾部标题
*/
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
if (section ==0) {
return@"世界一流品牌";
} elseif(section ==1) {
return@"牛逼哄哄";
} else {
return@"价格昂贵";
}
}
@end
- UITableView的基本用法
- UITableview的基本用法
- UITableView的基本用法
- UITableView的一些基本用法
- iOS开发 - UITableview的基本用法
- UITableView基本用法
- 32-UITableView基本用法
- 关于UITableView基本用法
- iOS tableView 控件用法 [0] UITableView的基本用法
- UITableView介绍 之 基本用法
- iOS学习笔记-026.UITableView的基本用法
- UITableView的基本使用
- UITableView 的基本使用
- UITableView 的基本使用
- UITableView的基本使用方法
- UITableView的用法
- UITableView的用法详解
- UITableView的用法实例
- 关于C++的深拷贝与浅拷贝
- HDU1052 Tian Ji -- The Horse Racing(贪心)
- hduoj 1025对上升子序列的时间复杂度优化
- 软件测试的精明刑警
- nodejs安装以及npm命令大全
- UITableView的基本用法
- mysql 5.xx 安装说明 (zip免安装的)
- Retrofit完全解析(二):泛型(Generic)
- linux lsof命令详解
- 人人都该懂点儿TCP
- java练习1——识别字符串中出现英文字母的次数
- 20161027 记录
- shopnc IM 配置服务器地址
- 达内学习笔记——MFC绘图对象