****加上数据分离

#import "HMViewController.h"
#import "HMStudent.h" @interface HMViewController () <UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView; /** 数据列表 */
@property (nonatomic, strong) NSArray *dataList;
@end @implementation HMViewController - (NSArray *)dataList
{
if (_dataList == nil) {
HMStudent *stu1 = [[HMStudent alloc] init];
stu1.title = @"黑马1期";
stu1.desc = @"牛叉"; // 生成编号数组
NSMutableArray *arrayM1 = [NSMutableArray array];
for (int i = ; i < ; i++) {
[arrayM1 addObject:[NSString stringWithFormat:@"%@ - %04d", stu1.title, i]];
}
stu1.students = arrayM1; HMStudent *stu2 = [[HMStudent alloc] init];
stu2.title = @"黑马2期";
stu2.desc = @"也牛叉"; // 生成编号数组
NSMutableArray *arrayM2 = [NSMutableArray array];
for (int i = ; i < ; i++) {
[arrayM2 addObject:[NSString stringWithFormat:@"%@ - %04d", stu2.title, i]];
}
stu2.students = arrayM2; _dataList = @[stu2, stu1];
}
return _dataList;
} #pragma mark - 数据源方法
// 如果没有实现,默认是1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.dataList.count;
} // 每个分组中的数据总数
// sction:分组的编号
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// students数组中的元素数量
// 取出数组中对应的学员信息
// HMStudent *stu = self.dataList[section];
// return stu.students.count;
// 计算数量的代码,由于层次比较深,建议使用上面的代码
return [[self.dataList[section] students] count];
} // 告诉表格控件,每一行cell单元格的细节
// indexPath
// @property(nonatomic,readonly) NSInteger section; 分组
// @property(nonatomic,readonly) NSInteger row; 行
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 实例化TableViewCell时,使用initWithStyle方法来进行实例化
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; // 取出indexPath对应的数据
HMStudent *stu = self.dataList[indexPath.section]; cell.textLabel.text = stu.students[indexPath.row]; return cell;
} // 返回分组的标题文字
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
// HMStudent *stu = self.dataList[section];
// return stu.title;
return [self.dataList[section] title];
} - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
// HMStudent *stu = self.dataList[section];
// return stu.desc;
// 直接从数组中取出的对象是id类型,因为没有明确的类型,因此不能使用.语法,只能使用getter方法
return [self.dataList[section] desc];
} @end

IOS第七天(2:UiTableView 加上数据分离)的更多相关文章

  1. IOS第七天(3:UiTableView 模型和数据的分组的显示)

    *************UiTableView模型和数据的分组的显示 #import "HMViewController.h" #import "HMHero.h&qu ...

  2. IOS第七天(4:UiTableView 数据的显示优化重复实例和tableFooterView和tableHeaderView)

    //加上头部 和底部 - (void)viewDidLoad { [super viewDidLoad]; [self tableView]; // 设置行高 self.tableView.rowHe ...

  3. IOS第七天(6:UiTableView编辑模式, 拖动位置 ,滑动删除)

    **********UiTableView编辑模式, 拖动位置 ,滑动删除 #import "HMViewController.h" @interface HMViewContro ...

  4. IOS第七天(5:UiTableView 汽车品牌,复杂模型分组展示,A-Z索要列表) (2015-08-05 14:03)

    复杂模型分组展示 #import "HMViewController.h" #import "HMCarGroup.h" #import "HMCar ...

  5. IOS第七天(1:UiTableView 的基本用法)

    ***表格控件 #import "HMViewController.h" @interface HMViewController () <UITableViewDataSou ...

  6. IOS开发之表视图(UITableView)

    IOS开发之表视图(UITableView)的基本介绍(一) (一):UITableView的基本概念 1.在IOS开发中,表视图的应用十分广泛和普及.因此掌握表视图的用法显得非常重要.一般情况下对于 ...

  7. iOS全埋点解决方案-UITableView和UICollectionView点击事件

    前言 在 $AppClick 事件采集中,还有两个比较特殊的控件: UITableView •UICollectionView 这两个控件的点击事件,一般指的是点击 UITableViewCell 和 ...

  8. iOS开发UI篇—实现UItableview控件数据刷新

    iOS开发UI篇—实现UItableview控件数据刷新 一.项目文件结构和plist文件 二.实现效果 1.说明:这是一个英雄展示界面,点击选中行,可以修改改行英雄的名称(完成数据刷新的操作). 运 ...

  9. iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)

    iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一) 一.项目结构和plist文件 二.实现代码 1.说明: 主控制器直接继承UITableViewController // ...

随机推荐

  1. hdu 3449 有依赖性的01背包

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3449  Consumer Description FJ is going to do so ...

  2. Codeforces Round #375 (Div. 2) - B

    题目链接:http://codeforces.com/contest/723/problem/B 题意:给定一个字符串.只包含_,大小写字母,左右括号(保证不会出现括号里面套括号的情况),_分隔开单词 ...

  3. C++11 std::chrono库详解

    所谓的详解只不过是参考www.cplusplus.com的说明整理了一下,因为没发现别人有详细讲解. chrono是一个time library, 源于boost,现在已经是C++标准.话说今年似乎又 ...

  4. 《HBase实战》

    对,我正在研读这本书,今天开始,我希望我看完后能有收获和大家分享,这个日志作为开始,勉励自己! 对,我应该静下心,做一些我更喜欢的事情,不能在自我陶醉中迷失! 断断续的看,到今天大概把这本书看完了,没 ...

  5. HDU5461 Largest Point(暴力)

    这题第一眼就想到暴力.. 枚举每一个ti,就能确定tj,tj一定是剩下数最大或最小的.为了求tj就要求出数列最大最小次大次小.时间复杂度O(n). 感觉暴力挺有趣的. #include<cstd ...

  6. 每天一个linux命令--more/less

    最近小编在和第三方调试接口,只能查日志,查询除了tail,grep,cat,之外,还有 more.less,他们的优点在于可以翻页. more最基本的指令就是按空白键(space)就往下一页显示,按  ...

  7. BZOJ4657 : tower

    显然只有横向和纵向的两个炮塔才有可能冲突. 考虑最小割,将每个炮塔所有能攻击到的位置建点,相邻之间连无穷的边,表示前缀和关系,即选了一个点,就必须要选所有比它近的点. 属于横向炮塔的点向$S$连边,容 ...

  8. 怎样测试TCP&UDP端口

    TCP端口大家都知道,比如80端口,可以使用 telnet ip 80,来验证端口是否正常监听,那UDP端口是否可以同样测试呢?详细如下: 下面我们来进行测试,123端口是服务器42.11.12.13 ...

  9. Android AsyncTask

    AsyncTask类任务管理: 内部会创建一个进程作用域的线程池来管理要运行的任务,也就就是说当你调用了AsyncTask#execute()后,AsyncTask会把任务交给线程池,由线程池来管理创 ...

  10. IOS学习笔记25—HTTP操作之ASIHTTPRequest

    IOS学习笔记25—HTTP操作之ASIHTTPRequest 分类: iOS2012-08-12 10:04 7734人阅读 评论(3) 收藏 举报 iosios5网络wrapper框架新浪微博 A ...