zoukankan      html  css  js  c++  java
  • UITableView调用的方法

    UITableView实现两个协议UITableViewDataSourceUITableViewDelegate

    #pragma mark 一共有多少行数据
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return self.data.count;

    #pragma mark 每一行显示什么数据
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {} 

    #pragma mark 设置某一行的高度
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{} 

    #pragma mark 点击了某一行的cell就会触发这个方法

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndex:(NSIndexPath *)indexPath{}

    //提交编辑操作时会调用这个方法

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{}

     //取出选中这一行

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    //取得对应位置的Cell对象

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    //让Cell打钩

    cell.accessoryType = UITableViewCellAccessoryCheckmark;

    //将分割线去掉

    tableView.separatorColor = [UIColor clearColor];

    //判断原来的Cell在不在集合里面,如果在就check,否则不check

    NSString *text = [self.data ObjectAtIndex:indexPath.row];

    if ([self.selectedData containsObject:text]){

      cell.accessoryType = UITableViewCellAccessoryCheckmark;

    } else {

      cell.accessoryType = UITableVIewCellAccessoryNone;

    }

    //循环利用的Cell

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];

    if(cell == nil){

      //如果没有可循环利用的Cell,就必须创建一个Cell

     cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier:@"UITableVIewCell"] autorelease];

    }

     //重新向dataSrouce请求数据

    //重新调用数据源的方法numberOfRowsInSection和cellForRowAtIndexPath

    [tableview reloadData];

     //更新UI并有动画效果

    [self.tableView deleteRowsAtIndexPaths:self.selectedRows

     withRowAnimation:UITableViewRowAnimationAutomatic];

    //清除数组中的数据

    [removeAllObjects];

  • 相关阅读:
    重装系统之后应装软件
    中文乱码解决方案
    买电脑需要考虑的电脑配置
    JavaBean个人总结
    Servlet个人总结
    web.xml详解
    默认软件
    Eclipse导入项目
    Eclipse插件安装
    Tomcat详解
  • 原文地址:https://www.cnblogs.com/wangshengl9263/p/3067272.html
Copyright © 2011-2022 走看看