zoukankan      html  css  js  c++  java
  • iOS UITableView的一些方法

    项目中用到的一些tabview 问题及对应方法:

    一.tableview

    1.下划线左对齐

    //步骤一:(加在 viewdidload方法中)
        if([tabView respondsToSelector:@selector(setSeparatorInset:)])
        {
            [tabView setSeparatorInset:UIEdgeInsetsZero];
        }
        if
            ([tabView respondsToSelector:@selector(setLayoutMargins:)])
        {
            [tabView setLayoutMargins:UIEdgeInsetsZero];
        }
    //步骤二:修改分割线方法 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { [cell setSeparatorInset:UIEdgeInsetsZero]; } if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { [cell setLayoutMargins:UIEdgeInsetsZero]; } }

    二.cell

    1.自定义cell获取选中的cell

    NSIndexPath *indexPath = [tabView indexPathForSelectedRow];
    UITableViewCell
    *cell = [tabView cellForRowAtIndexPath:indexPath]; cell.myLable.text= @"abc";

    2.下拉列表单选(文字选中变色等)

    //选中变色
    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSLog(@"选中某项变色");
        SortTableViewCell *cell = [tabView cellForRowAtIndexPath:indexPath];
        cell.sortLable.textColor = RGBCOLOR(51, 153, 204);
    }
    
    //再次点击取消
    -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSLog(@"取消某项变色");
        SortTableViewCell *cell = [tabView cellForRowAtIndexPath:indexPath];
        cell.sortLable.textColor = [UIColor blackColor];
    }

    补充:如果还要默认选中第一项同时还得触发触发didselect方法  用以下方法

    NSIndexPath *firstPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [tabView selectRowAtIndexPath:firstPath animated:YES scrollPosition:UITableViewScrollPositionTop];
     if ([tabView.delegate respondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)]) {
          [tabView.delegate tableView:tabView didSelectRowAtIndexPath:firstPath];
    }

    3. cell的单选和多选

    项目需要做试题的单选和课程下载的多选,首先想到用tabview的didselect配合didDeselect两个协议的方法(参考:http://www.2cto.com/kf/201412/364359.html),后来没用;

    因为试题ABCD四个选项的单选题样式 所以在cell中加上button按钮解决;而下载是有分区的多选样式就根据下载图片的前后位置不同分别采取了cell加button的方法和系统自带的编辑方法

    4.取消多余空白cell

    tabView.tableFooterView = [[UIView alloc] init];//去掉空白cell

    5.点击效果

    (1).自定义点击时的背景色

    UIView *view = [[UIView alloc]init];
    view.backgroundColor =  RGBCOLOR(229, 246, 254);
    cell.selectedBackgroundView = view;

    (2).点击后返回cell的颜色为无色

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    (3).点击时有颜色变化 返回cell的颜色为无色(配合自定义cell选中背景色)

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [tableView deselectRowAtIndexPath:indexPath animated:NO];
    }

    三.混合嵌套

    1.tableview二级菜单

  • 相关阅读:
    学英语舌尖效应(转)
    winform程序防止重复运行
    label字符自动换行(转自网络)
    C# WINFORM中的combobox.items.add实现像web开发那样,添加显示内容text和实际value值
    三极管开关电路设计(转)
    ASPNET+ArcGIS+Flex初次使用笔记
    转:oracle日期函数集锦
    网站开发人员应该知道的62件事
    cassandra的安装与使用
    datejs一个很好用的时间日期JavaScript组件
  • 原文地址:https://www.cnblogs.com/wusang/p/5619518.html
Copyright © 2011-2022 走看看