UITableView取消选中颜色、常用操作

 

使用空白view取代cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

  //取消选中颜色

  UIView *backView = [[UIView alloc] initWithFrame:cell.frame];
  cell.selectedBackgroundView = backView;
  cell.selectedBackgroundView.backgroundColor = [UIColor clearColor];

  //取消边框线

  [cell setBackgroundView:[[UIView alloc] init]];          //取消边框线
      cell.backgroundColor = [UIColor clearColor];

//在navigation中tableviewCell选中后返回无选中项

//单击一个cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath]; 
    if(cell.tag == 0){

   //注销cell单击事件
        cell.selected = NO;
    }else {
        [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];  //取消选中项
        BabyScheduler *babyScheduler=[listData objectAtIndex:indexPath.row-1];
        [delegate showVaccinationView:babyScheduler];    
    }
}

- (void)viewDidLoad
{
    self.title = NSLocalizedString(@"TempGroupViewTitle", @"");
    self.view.backgroundColor=[UIUtils defaultViewBackground];
    self.tempGroupTableView.backgroundColor=[UIColor clearColor];
    self.tempGroupTableView.separatorColor=[UIColor clearColor];    //分割cell线颜色
    self.tempGroupTableView.separatorStyle=UITableViewCellSeparatorStyleNone;   //不带分割线样式
    self.tempGroupTableView.rowHeight=45.0;
    
    self.navigationItem.rightBarButtonItem = self.editButtonItem;   //添加navigation按钮
    self.groupList = [DBManager selectTempGroup];   //获取分组信息
//    NSLog(@"-----%d",[groupList count]);
    [super viewDidLoad];
}

if (!cell)----当cell为空?真:假

//设置cell的高度

#pragma mark - Table view delegate
-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section==1)return 45;
    return 0;
}

//返回自定义hrader
-(UIView*) tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section==1) { //第二区
        UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 305, 38)];
        UIImageView* backgroundView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title.png"]];
        backgroundView.frame=CGRectMake(0, 0, 123, 38);
        [view addSubview:backgroundView];
        [backgroundView release];
        view.backgroundColor=[UIColor clearColor];
        UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(30, 0, 93, 38)];
        label.backgroundColor=[UIColor clearColor];       
        label.textColor=[UIColor whiteColor];
        label.text=NSLocalizedString(@"Section_Title_My_Group_Name", @"");
        [view addSubview:label];
        [label autorelease];
        return  [view autorelease];
    }
    return nil;
}

//向tableview填充数据
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //当第一个分区得最后一行
    if ((indexPath.section==0)&&(indexPath.row==[groupList count])) {
        static NSString *AddGroupViewCellIdentifier = @"AddGroupViewCell";
        
        UITableViewCell *cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AddGroupViewCellIdentifier] autorelease];
        // key 说明性文字
        cell.textLabel.text=NSLocalizedString(@"Add_New_Group", @"add new group");
        cell.textLabel.backgroundColor=[UIColor clearColor];
        cell.textLabel.textAlignment=UITextAlignmentCenter;     //cell中text文本居中
        cell.backgroundColor=[UIUtils defaultContactCellBackgroundColor];
        cell.tag=-1;
        return  cell;
    }
    static NSString *SimpleTableIdentifier = @"GroupListViewCell";
    //使用自定义cell
    //查找SimpleTableIdentifier的cell,为空初始化
    GroupListViewCell *cell = (GroupListViewCell *)[tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
    if (!cell)
    {
        [[NSBundle mainBundle] loadNibNamed:SimpleTableIdentifier owner:self options:nil];
        cell = groupCell;
        cell.backgroundColor=[UIUtils defaultContactCellBackgroundColor];
        self.groupCell = nil;        
    }
    cell.group=[groupList objectAtIndex:indexPath.row];

//设置cell右边箭头,v等等,有枚举变量可供选择
//    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    NSUInteger row = [indexPath row];
    cell.tag = row;
    [SimpleTableIdentifier release];
    return cell;
    
}

cell可删除

// 指定tableview可删除的区域
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return indexPath.section==1?YES:NO;
}
//可删除的cell
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView
          editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSUInteger row = [indexPath row];
    if (row == [groups count]) {
        return UITableViewCellEditingStyleNone;
    }else {
        return UITableViewCellEditingStyleDelete;
    }
}

// 删除之后
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [self deleteGroup:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}

//当前选中行设为非选中

[self.membersListView deselectRowAtIndexPath:membersListView.indexPathForSelectedRow animated:YES];

 
本文转载至:http://www.cnblogs.com/zcw-ios/articles/2574372.html

UITableView取消选中颜色、常用操作的更多相关文章

  1. UITableView 之 取消选中

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [table ...

  2. jQuery操作复选框checkbox技巧总结 ---- 设置选中、取消选中、获取被选中的值、判断是否选中等

    转载:https://blog.csdn.net/chenchunlin526/article/details/77448168 jQuery操作复选框checkbox技巧总结 --- 设置选中.取消 ...

  3. UITableView取消cell选中状态关于deselectRowAtIndexPath

    有没有遇到过,导航+UITableView,在push,back回来之后,当前cell仍然是选中的状态. 当然,解决办法简单,添加一句[tableView deselectRowAtIndexPath ...

  4. jquery操作checkBox 一次取消选中后不能再选中

    $("input[type='checkbox']").each(function(){ $(this).attr("checked","checke ...

  5. 用ArcGIS?37个Arcmap常用操作技巧可能帮到您

    1. 要素的剪切与延伸 实用工具 TASK 任务栏 Extend/Trim feature 剪切所得内容与你画线的方向有关. 2. 自动捕捉跟踪工具 点击Editor工具栏中Snapping来打开Sn ...

  6. DataGridView常用操作

    一.DataGridView列右击菜单事件处理 (1). 添加一个快捷菜单contextMenuStrip1:(2). 给dataGridView1的CellMouseDown事件添加处理程序: pr ...

  7. [编辑器]vim常用操作

    我是ide的用户,对于vim一只停留在:打开.看.写.关闭基本操作,因为现在更多的接触linux服务器,所以为了提高 效率,用好vim是必备技能!下面罗列一些vim的常用操作,用做备忘(不断更新): ...

  8. fiddler常用操作之断点

    fiddler常用操作断点 标签(空格分隔): fiddler断点 一.断点: 1.为什么要打断点呢? 比如一个购买的金额输入框,输入框前端做了限制100-1000,那么我们测试的时候,需要测试小于1 ...

  9. python+selenium实现动态爬取及selenuim的常用操作

    应用实例可以参考博客中的12306自动抢票应用 https://www.cnblogs.com/mumengyun/p/10001109.html 动态网页数据抓取 什么是AJAX: AJAX(Asy ...

随机推荐

  1. python学习笔记(22)--漫画生成html最终版

    说明(2017.3.14): 1. 在主文件夹生成一个main.html作为目录 2. 在每个子文件夹生成一个index.html作为看图网页 3. 通过python批量生成html网页,js配合进行 ...

  2. spark.Accumulator

    scala> val accum = sc.accumulator() accum: org.apache.spark.Accumulator[Int] = scala> sc.paral ...

  3. 【C#】复制物体后,给副本命名的规则——用正则表达式

    需求:已经实现物体复制功能后,给新生成的副本进行命名. 问题:因为副本也能被复制,即副本的副本,所以复制品的命名规则会如下图所示. 尝试过用for循环和递归,发现在for循环内部递归返回的话会有问题, ...

  4. 【转】【C#】判断当前操作系统

    写一个判断操作系统的工具类OSHelper.cs public class OSHelper { // 获取操作系统ID public static System.PlatformID GetPlat ...

  5. mysql 5.7.12----bin/mysqld --initialize --user=mysql出错

    我最近在安装mysql 5.7.12,本来之前安装mysql 5.7.11时用命令 bin/mysqld --initialize --user=mysql 可以很好的初始化,但是用在5.7.12版本 ...

  6. JavaScrip——DOM操作(属性操作)

    Attribute a.setAttribute("属性名","属性值")——设置属性 a.getSttribute("属性名")——获取属 ...

  7. nfs简述

    参考:http://www.51lun-wen.cn/shenghuo/dianniaowangluo/diannaowangluo/czxt/Linux/200810/354248.html 1.什 ...

  8. iOS边练边学--简单的数据操作(增、删、改),左滑动删除和弹窗

    一.数据刷新的原则: 通过修改模型数据,来修改tableView的展示 先修改数据模型 在调用数据刷新方法 不要直接修改cell上面子控件的属性 二.增删改用到的方法: <1>重新绑定屏幕 ...

  9. R语言进阶之4:数据整形(reshape)

    一.通过重新构建数据进行整形 数据整形最直接的思路就把数据全部向量化,然后按要求用向量构建其他类型的数据.这样是不是会产生大量的中间变量.占用大量内存?没错.R语言的任何函数(包括赋值)操作都会有同样 ...

  10. C++11 新特性:Lambda 表达式

    参考文章:https://blogs.oracle.com/pcarlini/entry/c_1x_tidbits_lambda_expressions 或许,Lambda 表达式算得上是 C++ 1 ...