zoukankan      html  css  js  c++  java
  • tableView小细节

    1.取消cell点击变色

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    2.禁止边缘滑动(类似到顶端仍可拖动一小节)

    talbeview.bounces = NO;

    3.设置分界线颜色

    tableView.separatorColor  = [UIColor clearColor];//透明,达到没有分界线效果

    4.标题

    Label加载在View  return View 才能实现自定义Labelframe, return label不能改变frame

    5.获得当前屏幕显示的所有行

     [mTableView  indexPathsForVisibleRows]

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

        NSString *HeaderString = nil;

        switch (section) {

            case 0:

                HeaderString=@"1";

                break;

            case 1:

                HeaderString= @"2";

                break;

            default:

                HeaderString= @"3";

                break;

    }

        UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)] autorelease];

        headerView.backgroundColor = [UIColor clearColor];

        UILabel *HeaderLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 200, 40)];

        HeaderLabel.backgroundColor = [UIColor clearColor];

        HeaderLabel.font = [UIFont boldSystemFontOfSize:17];

        HeaderLabel.textColor = [UIColor whiteColor];

        HeaderLabel.text = HeaderString;

        [headerView addSubview:HeaderLabel];

        [HeaderLabel release];

        return headerView;

    }

    同理:

    - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

    6.

    实现右侧的小灰色箭头  只要将cell的accessoryType属性设置为

    UITableViewCellAccessoryDisclosureIndicator就可以了。

    代码为:cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;

    其他格式:像对勾、删除什么类似,更改一下属性值即可

    二、UITableView各Method说


    //Section总数
    - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
     return TitleData;
    }


    // Section Titles
    //每个section显示的标题
    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
     return @"";
    }


    //指定有多少个分区(Section),默认为1
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
     return 4;
    }


    //指定每个分区中有多少行,默认为1
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    }


    //绘制Cell
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
      
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
                                 SimpleTableIdentifier];
     
       if (cell == nil) {  
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                           reuseIdentifier: SimpleTableIdentifier] autorelease];

     }
     cell.imageView.image=image;//未选cell时的图片
     cell.imageView.highlightedImage=highlightImage;//选中cell后的图片
     cell.text=//.....
     return cell;
    }


    //行缩进
    -(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath{
     NSUInteger row = [indexPath row];
     return row;
    }


    //改变行的高度
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        return 40;
    }


    //定位
    [TopicsTable setContentOffset:CGPointMake(0, promiseNum * 44 + Chapter * 20)];


    //返回当前所选cell
    NSIndexPath *ip = [NSIndexPath indexPathForRow:row inSection:section];
    [TopicsTable selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionNone];


    [tableView setSeparatorStyle:UITableViewCellSelectionStyleNone];


    //选中Cell响应事件
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

     [tableView deselectRowAtIndexPath:indexPath animated:YES];//选中后的反显颜色即刻消失
    }


    //判断选中的行(阻止选中第一行)
    -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSUInteger row = [indexPath row];
        if (row == 0)
            return nil; 
        return indexPath;
    }


    //划动cell是否出现del按钮
    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    }


    //编辑状态
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
    forRowAtIndexPath:(NSIndexPath *)indexPath
    {

    [topicsTable setContentSize:CGSizeMake(0,controller.promiseNum * 44)];
    //右侧添加一个索引表
    - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{


    //返回Section标题内容
    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    }

    //自定义划动时del按钮内容
    - (NSString *)tableView:(UITableView *)tableView
    titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath


    //跳到指的row or section
    [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];

    三、在UITableViewCell上建立UILable多行显示


    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *CellIdentifier = @"Cell";   
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
      UILabel *Datalabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 320, 44)];
      [Datalabel setTag:100];
      Datalabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
      [cell.contentView addSubview:Datalabel];
      [Datalabel release];
     } 
     UILabel *Datalabel = (UILabel *)[cell.contentView viewWithTag:100];
     [Datalabel setFont:[UIFont boldSystemFontOfSize:18]];
     Datalabel.text = [data.DataArray objectAtIndex:indexPath.row];
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return cell;
    }

    //选中cell时的颜色

    typedef enum {
        UITableViewCellSelectionStyleNone,
        UITableViewCellSelectionStyleBlue,
        UITableViewCellSelectionStyleGray
    } UITableViewCellSelectionStyle

    //cell右边按钮格式

    typedef enum {
        UITableViewCellAccessoryNone,                   // don't show any accessory view
        UITableViewCellAccessoryDisclosureIndicator,    // regular chevron. doesn't track
        UITableViewCellAccessoryDetailDisclosureButton, // blue button w/ chevron. tracks
        UITableViewCellAccessoryCheckmark               // checkmark. doesn't track
    } UITableViewCellAccessoryType

    //是否加换行线

    typedef enum {
        UITableViewCellSeparatorStyleNone,
        UITableViewCellSeparatorStyleSingleLine
    } UITableViewCellSeparatorStyle

     

    //改变换行线颜色lyttzx.com

    tableView.separatorColor = [UIColor blueColor];

     //点中选择时cell显示未蓝色 松开后为原来颜色

     [mTableViewdeselectRowAtIndexPath:[mTableViewindexPathForSelectedRow] animated:YES];

    UITableViewStyleGrouped类型的UITableView中出现,UITableViewStylePlain类型的tableView没有这个问题,因为Group类型的TableView有个backgroundView,而plain类型的TableView没有(backgroundView属性为nil),目前看来,这可能因为backgroundView在中间挡住了背景色,这是否iOS6的bug还待确认。关于backgroundView,还可以参考下这里iPad Table backgroundView

    目前对于这个问题的解决方法是将Group类型的tableView的backgroundView设为一个新的空白View或简单的设置为nil.如下

    tableView.backgroundView = [[UIView alloc]init];
    tableView.backgroundColor = [UIColor clearColor];

    tableView.backgroundView = nil;
    tableView.backgroundColor = [UIColor clearColor];
     
  • 相关阅读:
    SDN概述
    Linux企业运维人员必备150个命令汇总
    自动化运维工具puppet详解(二)
    自动化运维工具puppet详解(一)
    自动化运维工具[ansible详解三]
    ansible 常用模块
    自动化运维工具【ansible详解 二】
    A. Cinema Line
    A. Wrong Subtraction
    A. The number of positions
  • 原文地址:https://www.cnblogs.com/Cristen/p/2779142.html
Copyright © 2011-2022 走看看