Table View 学习
2015-06-19 16:58
323 查看
源码下载
一直在考虑这个拖在那里,在看老的视频的时候直接拖在file's owner 但是在新故事版中不存了,所以一直纠结中,无论拖在那里都是错误的。
通过代码写仿佛也错误。
主要实现的几个方法如下:
// 用于返回table view有多少行。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [myar1 count];
}
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
//用于显示有行,这里有一个性能问题,就是当拖动的时候显示性能问题。要新创建一个cell。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *TableSampleIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
TableSampleIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:TableSampleIdentifier];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [myar1 objectAtIndex:row];
UIImage *image = [UIImage imageNamed:[myar2 objectAtIndex:
row]];
cell.imageView.image =image;
return cell;
}
显示效果:
显示组用这个:
// 选择相应的行用
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if([indexPath section]==0){
//直接有 section用section 选择
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//return [myar1 count];
if (section==0) {
//分段标题
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
if(section==0){
return @"test1";
}else{
return @"test3";
}
}
一直在考虑这个拖在那里,在看老的视频的时候直接拖在file's owner 但是在新故事版中不存了,所以一直纠结中,无论拖在那里都是错误的。
通过代码写仿佛也错误。
主要实现的几个方法如下:
// 用于返回table view有多少行。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [myar1 count];
}
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
//用于显示有行,这里有一个性能问题,就是当拖动的时候显示性能问题。要新创建一个cell。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *TableSampleIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
TableSampleIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:TableSampleIdentifier];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [myar1 objectAtIndex:row];
UIImage *image = [UIImage imageNamed:[myar2 objectAtIndex:
row]];
cell.imageView.image =image;
return cell;
}
显示效果:
显示组用这个:
// 选择相应的行用
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if([indexPath section]==0){
//直接有 section用section 选择
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//return [myar1 count];
if (section==0) {
//分段标题
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
if(section==0){
return @"test1";
}else{
return @"test3";
}
}
相关文章推荐
- 腾讯云搜纠错(QC)系统----用户的每一次错误搜索都能获得惊喜
- OJ积累--商品销售
- 查看树莓派的CPU温度
- Android的第二次增加SurfaceView基本使用
- JAVA 安全性转码代码(包括sql注入,跨站脚本)
- 解决gnuplot中'Terminal type set to 'unknown'不能显示绘图的问题
- COPRA RF 2005 SR1最新版 (冷弯成型,轧辊设计)
- 自适应屏幕大小的网页是怎么做出来的
- Rhel6.5_Nginx1.45_Php5.59_MySQL5.6.16编译安装(集成LNMP环境)
- 获取日志$6到$NF的字段
- Android Choreographer 源码笔记
- Android Studio开发JNI工程
- 使用向量的方法计算点到直线的距离
- 一步步走进Android MaterialDesign 之 DrawerLayout
- How to install ipsec-tools on RHEL6
- bat批量目光声明
- 【Training versus Testing】林轩田机器学习基石
- 114 Flatten Binary Tree to Linked List 二叉树到单链表的扁平化处理
- IOS prepareForSegue 多窗口切换学习
- 如何编译&使用boost库?