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. 纯css3实现的3D按钮

    前面已经为大家介绍了好多纯css3实现的按钮.今天要再给大家带来一款纯css3实现的3D按钮.在实例中给出了五种颜色的3D按钮.效果图如下: 在线预览   源码下载 实现的代码. html代码: &l ...

  2. 【WPF】查找父/子控件(元素、节点)

    整理一下项目中常用的找控件功能,包括找父/子控件.找到所有同类型子控件(比如ListBox找到所有Item). using System; using System.Collections.Gener ...

  3. buildroot 使用本地交叉编译器记录

    继上一次glibc bug 事件后,剑锋就说文件系统要用统一的交叉编译器.所以今天就试了一下,便记录一下 在官网下载干净的 buildroot 进入解压后的 buildroot 目录 步骤: make ...

  4. signal(SIGPIPE, SIG_IGN) (转)

    signal(SIGPIPE, SIG_IGN) 当服务器close一个连接时,若client端接着发数据. 根据TCP 协议的规定,会收到一个RST响应,client再往这个服务器发送数据时,系统会 ...

  5. CAS (4) —— CAS浏览器SSO访问顺序图详解(CAS Web Flow Diagram by Example)

    CAS (4) -- CAS浏览器SSO访问顺序图详解(CAS Web Flow Diagram by Example) tomcat版本: tomcat-8.0.29 jdk版本: jdk1.8.0 ...

  6. drupal7请求异常,执行时间过长的解决方法

    drupal7请求错误,执行时间过长的解决办法 根据你的系统或网络设置Drupal不能读取网页,造成功能缺失.可能是web服务器配置或PHP设置引起的,可用更新.获取更新源.使用OpenID登 录或使 ...

  7. eclipse-设置默认编码格式为UTF-8

    需要设置的几处地方为: Window->Preferences->General ->Content Type->Text->JSP 最下面设置为UTF-8 Window ...

  8. chrome 常用快捷键(可以摆脱鼠标哦)

      Ctrl+N                                打开新窗口. Ctrl+T                                打开新标签页. Ctrl+Sh ...

  9. 在DHTML中把整个文档的各个元素作为对象处理的技术是:()

    在DHTML中把整个文档的各个元素作为对象处理的技术是:() A.HTML B.CSS C.DOM D.Script(脚本语言) 解答:C DOM:文档对象模型

  10. 如何使用GameObject类发送消息

    一.GameObject发送消息的方法 GameObject类有三个方法可以实现发送消息,即SendMessage.BroadcastMessage和SendMessageUpwards.但是它们之间 ...