• 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];

  • 相关阅读:
    Integer值判断是否相等问题
    Java连接Redis
    oracle 10G 没有 PIVOT 函数怎么办,自己写一个不久有了
    前端修炼(第三天)函数
    前端 JS 修炼(第一天)包装对象、作用域、创建对象
    linux oracle 启动全过程
    「android」webview中文乱码
    「dos」bat单条命令跨多行
    「股票」东方财富网公式-缩量
    「android」as javadoc乱码
  • 原文地址:https://www.cnblogs.com/howdoudo/p/4274925.html
Copyright © 2020-2023  润新知