//
// 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的总结的更多相关文章

  1. iOS有关横向TableView的东西

    之前看到Apple store里面有横向的tableview,当然也有可能是collectionview啦. 尤其是项目中只有一条那么需要横向滑动的东西,就没有必要使用庞大的collectionvie ...

  2. tableView显示第一个cell有偏移问题

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 0 ...

  3. [tableView reloadData] 和 runloop

    需要[tableView reloadData]后需要立即获取tableview的cell.高度,或者需要滚动tableview,那么,直接在reloadData后执行代码是会有问题的. 断点调试感觉 ...

  4. 【代码笔记】iOS-一个tableView,两个section

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  5. 【Swift】Alamofile网络请求数据更新TableView的坑

    写这篇BLOG前,有些话不得不提一下,就仅当发发恼骚吧... 今天下午为了一个Alamofire取得数据而更新TableView的问题,查了一下午的百度(360也是见鬼的一样),竟然没有一个简单明了的 ...

  6. TableView 滑动收起键盘

    self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; 拖拽tableView就会收起键盘

  7. 关于TableView上有一段留白的解决方法

    当cell的类型是plaint类型时 直接设置self.automaticallyAdjustsScrollViewInsets=NO; 还有要注意检查你自己设置的frame是否正确     当cel ...

  8. iOS监听tableView组头切换事件

    - (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSIntege ...

  9. 【原】iOS学习之tableView的常见BUG

    1.TableView头视图不随视图移动,头视图出现错位 错误原因:tableView的 UITableViewStyle 没有明确的声明 解决方法:在tableView声明的时候明确为 UITabl ...

  10. 两种让tableview返回顶部的方法

    1. [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:_currentRow inSection:0] animat ...

随机推荐

  1. 19、手把手教你Extjs5(十九)模块Grid的其他功能的设想

    经过对自定义模块和Grid的设计和编码,现在已经能对一个有配置信息的模块来生成界面并进行一些简单的CURD操作.由于这是一个全解释性的前台的架构,因此你想到的任何新主意都可以放到所有的模块中. 比如对 ...

  2. memcache数据组织

    转自:原链接 使用命令 set(key, value) 向 memcached 插入一条数据, memcached 内部是如何组织数据呢 一 把数据组装成 item memcached 接受到客户端的 ...

  3. phpMyAdmin安装与配置(涉及LAMP配置)

    作者:zccst 安装一个phpMyAdmin还真麻烦,遇到很多问题.不过在解决过程中发现,PHP的水还真深,不是短时间可以看透的. 1,下载 建议去百度软件中心下载 2,使用 (1)解压后,复制配置 ...

  4. Java ThreadFactory接口用法

    根据需要创建新线程的对象.使用线程工厂就无需再手工编写对 new Thread 的调用了,从而允许应用程序使用特殊的线程子类.属性等等.   JDK中的介绍: An object that creat ...

  5. 10.8.5如何升级(app store 出错 请稍后重试 100)

    出现问题:苹果以前的老版本,OS X 10.8或是10.8.5在当年提示你升级,你又任性没升级的时候,拖过那阵,你再想升级,就是各种报复.进app store下载或是更新东西都是弹出app stpre ...

  6. 【转】2015年薪酬大涨的15个IT岗位

    近日,国外科技 IT 招聘公司 Robert Half 分析了 70 个科技职位后发现 2015 年从事 IT 从业人员的平均起薪将攀升至 5.7%,其中 15 个职位的提升潜力最大. 当企业在招聘过 ...

  7. sqlserver递归查询

    --递归查询 with cte as ( ' union all select k.id,k.Text, k.name,k.pid from Menu k inner join cte c on c. ...

  8. bzoj1070————2016——3——14

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1070: 题目概括: Description 同一时刻有N位车主带着他们的爱车来到了汽车维修中 ...

  9. WebGIS中通过行列号来换算出多种瓦片的URL 之离线地图(转载)

    WebGIS中通过行列号来换算出多种瓦片的URL 之离线地图 1.前言 在前面我花了两个篇幅来讲解行列号的获取,也解释了为什么要获取行列号.在这一章,我将把常见的几种请求瓦片时的URL样式罗列出来,并 ...

  10. JSP编译为Java类

    JSP编译为Java类: 注意可以随便写import的内容:可以写类属性.方法.main函数.内部类:可以使用内部类: JSP: <%@ page language="java&quo ...