zoukankan      html  css  js  c++  java
  • IOS--常用控件--UITableView

    1.去除多余的空白单元格

    //去除多余的空白行

        UIView *view = [UIView new];

        view.backgroundColor = [UIColor clearColor];

        [tableView setTableFooterView:view];

        [view release];

    2.选中单元格后的反显颜色即刻消失

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
        //[tableView deselectRowAtIndexPath:indexPath animated:YES];//选中后的反显颜色即刻消失


    }

    3.让tableView定位到最下边一行

        if ([self.array count]>1) {

            //让tableView定位到最下边一行

            NSIndexPath* indexPath = [NSIndexPath indexPathForRow:[self.array count]-1 inSection:0];

            [self.myTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];

        }

    4.tableview刷新指定行

    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:currentCommentId inSection:0];

    NSArray *array=[[NSArray alloc] initWithObjects:indexPath, nil];

    //tableview刷新指定行,指定的行数应该放到一个array中,提供给该方法

    [myTableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationMiddle];

    5.定制选中单元格后的颜色

    UIView *cellSelectedBackview=[[UIView alloc] initWithFrame:cell.frame];

            cell.selectedBackgroundView=cellSelectedBackview;

            [cellSelectedBackview release];

            cell.selectedBackgroundView.backgroundColor=COLOR_WO_BACK;

    6.增加cell

     //先更新数据

     //更新ui(无需手动更新ui,insert会自动执行reloadData)

    NSIndexPath * indexPath = [NSIndexPath indexPathForRow:0 inSection:sender.tag];

                [self.myTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

    7.删除cell(利用动画,比较简单的方式)

          [CATransaction begin];

                    [CATransaction setCompletionBlock:^{

                        // animation has finished

                        [_myTableView reloadData];

                    }];

          // do some work

                    [_myTableView beginUpdates];

          //先更新数据

                    [_insurancePeopleArray removeObjectAtIndex:deleteIndex];

          //更新ui

                    NSIndexPath * indexPathOld = [NSIndexPath indexPathForRow:deleteIndex-10 inSection:0];

                    NSArray *array=[NSArray arrayWithObjects:indexPathOld, nil];

                    [self.myTableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];

                    [_myTableView endUpdates];

                    [CATransaction commit];

  • 相关阅读:
    谈谈ios内存管理--持续更新
    IOS整体框架介绍
    OC-精简解读 block
    解读自定义UICollectionViewLayout--感动了我自己
    内存管理-深浅拷贝之 copy和mutableCopy
    OC-socket使用介绍
    ios 调用系统打电话和发消息的功能
    Swift-扩展
    Java 之switch语句
    Java 键盘输入数据
  • 原文地址:https://www.cnblogs.com/howdoudo/p/4274925.html
Copyright © 2011-2022 走看看