tableView的总结
//
// ViewController.m
// TableViewController
//
// Created by 王妍 on 16/3/23.
// Copyright © 2016年 com.edong. All rights reserved.
// #import "ViewController.h"
#import "MyTableViewCell.h"
#import "MyXIBTableViewCell.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView *tableView;
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; //1.创建tableView
[self creatTableViewController]; //3.注册cell
// [self.tableView registerClass:[MyTableViewCell class] forCellReuseIdentifier:@"cell"];
//3.1 Xib 注册的cell
[self.tableView registerNib:[UINib nibWithNibName:@"MyXIBTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell_xib"];
} -(void)creatTableViewController
{
self.tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.view addSubview:self.tableView]; //2.设置代理 及实现代理方法
self.tableView.delegate = self;
self.tableView.dataSource = self; //3.tableView的属性 /*
UITableViewCellSeparatorStyleNone, 没有cell直接的那条线了
UITableViewCellSeparatorStyleSingleLine, 先在中间 但是短一点
UITableViewCellSeparatorStyleSingleLineEtched
*/
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; //分割线的颜色
self.tableView.separatorColor = [UIColor redColor];
//分割线的内边距(只能设置左右距离) 上 左 下 右 (设置上下没有用)
// self.tableView.separatorInset = UIEdgeInsetsMake(110, 200, 0, 50); //行高 (但是用代理方法设置的话 这个就不管用了)
self.tableView.rowHeight = 200;
}
#pragma mark----tableView的代理方法
//一个组有几行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
return 3;
}
//一共几个组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 5;
// return [self.dataArray[section] count];
}
//cell的重用池
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ // MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
MyXIBTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell_xib" forIndexPath:indexPath]; //给cell赋值
// cell.headImv.image = [UIImage imageNamed:@"1111.png"];
// cell.nameLable.text = @"aa"; return cell;
}
//头高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 50;
}
//尾高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 100;
} //头部试图
//-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
//{
// UIView *headView = [[UIView alloc] init];
// headView.frame = CGRectMake(0, 0, 0, 0);
// headView.backgroundColor = [UIColor redColor];
// return headView;
//} //尾部试图
//-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
//{
// UIView *footView = [[UIView alloc] init];
// footView.frame = CGRectMake(0, 0, 0, 0);
// footView.backgroundColor = [UIColor yellowColor];
// return footView;
//} //cell的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80; //不同cell的高度
// return [MyTableViewCell cellHeight];
}
//点击cell的方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ } //分区头标题
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [NSString stringWithFormat:@"第%ld个头标题",section];
} //分区尾标题
-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
return [NSString stringWithFormat:@"第%ld个尾标题",section];
} //索引
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return @[@"a",@"b",@"c"];
}
//指定哪些行可以被编辑
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row % 2 == 0) {
return YES;
}else{
return NO;
}
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
//一些tableView的 属性 //旁边的滚动条没有了
self.tableView.showsVerticalScrollIndicator = NO; //分割线的颜色
self.tableView.separatorColor = [UIColor redColor];
去掉cell的点击效果
cell.selectionStyle = 0;
tableView的总结的更多相关文章
- iOS有关横向TableView的东西
之前看到Apple store里面有横向的tableview,当然也有可能是collectionview啦. 尤其是项目中只有一条那么需要横向滑动的东西,就没有必要使用庞大的collectionvie ...
- tableView显示第一个cell有偏移问题
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 0 ...
- [tableView reloadData] 和 runloop
需要[tableView reloadData]后需要立即获取tableview的cell.高度,或者需要滚动tableview,那么,直接在reloadData后执行代码是会有问题的. 断点调试感觉 ...
- 【代码笔记】iOS-一个tableView,两个section
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- 【Swift】Alamofile网络请求数据更新TableView的坑
写这篇BLOG前,有些话不得不提一下,就仅当发发恼骚吧... 今天下午为了一个Alamofire取得数据而更新TableView的问题,查了一下午的百度(360也是见鬼的一样),竟然没有一个简单明了的 ...
- TableView 滑动收起键盘
self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; 拖拽tableView就会收起键盘
- 关于TableView上有一段留白的解决方法
当cell的类型是plaint类型时 直接设置self.automaticallyAdjustsScrollViewInsets=NO; 还有要注意检查你自己设置的frame是否正确 当cel ...
- iOS监听tableView组头切换事件
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSIntege ...
- 【原】iOS学习之tableView的常见BUG
1.TableView头视图不随视图移动,头视图出现错位 错误原因:tableView的 UITableViewStyle 没有明确的声明 解决方法:在tableView声明的时候明确为 UITabl ...
- 两种让tableview返回顶部的方法
1. [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:_currentRow inSection:0] animat ...
随机推荐
- 2016年最全面的VR资源盘点,不只有VR视频播放器还有具体到步骤的VR资源
2016年过去了,有多少人开始使用VR来观看我们喜欢的视频资源呢?比传统视频更高的沉浸感,甚至在VR眼镜的视角中,自己仿佛化生成视频中的主角一般.然而,这种体验只有VR眼镜还是不行的,还需要有一个VR ...
- NSCalendar 日历类
NSCalendar 日历类 Cocoa中对日期和时间的处理 NSCalendar (一) (2008-11-12 21:54:10) NSCalendar用于处理时间相关问题.比如比较时间前后.计算 ...
- UIAlertController 自定义输入框及KVO监听
UIAlertController极大的灵活性意味着您不必拘泥于内置样式.以前我们只能在默认视图.文本框视图.密码框视图.登录和密码输入框视图中选择,现在我们可以向对话框中添加任意数目的UITextF ...
- Java序列化与反序列化,文件操作
参考两篇博客: http://blog.csdn.net/moreevan/article/details/6697777 http://blog.csdn.net/moreevan/article/ ...
- Sublime Text 3 安装 Emmet 插件
首先安装 Package Control 1.通过快捷键 ctrl+` 或者 View > Show Console 菜单打开控制台 2.粘贴以下代码后回车安装 import urllib.r ...
- 1.2.Core Data 的适用场合(Core Data 应用程序实践指南)
如果应用程序要保存的设置数据太多,以致NSUserDefaults及“属性列表“(property list)这种简单的存储方案无法应付.不需要再"重新发明轮子"(reinvent ...
- Linux下的文件目录结构详解
Linux下的文件目录结构详解 / Linux文件系统的上层根目录 /bin 存放用户可执行的程序 /boot 操作系统启动时所需要的文件 /dev 接口设备文件目录,例如:had表示硬盘 /etc ...
- HDU-5123-who is the best?
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5123 水题一个,直接hash: 代码 #include<stdio.h>#include& ...
- JQuery flot API文档 中文版
调用plot函数的方法如下: var plot = $.plot(placeholder, data, options) 其 中placeholder可以是JQuery的对象,DOM元素或者JQuer ...
- IIS 启用w3wp.exe调试 没有找到w3wp进程
必须条件: 在进程列表的下面,有个show processes in all sessions,把它勾上就能看到了 . VS中附加进程的方式调试IIS页面,以及设置断点无效问题解决 以前调试网站的时候 ...