zoukankan      html  css  js  c++  java
  • UITableView-(单元格的自定义方法)

    //contentView

    //行内容
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        //从重用队列中取出闲置单元格
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        //判断cell是否为nil
        if (cell == nil) {
            //创建单元格的时候,要确保重用标示符跟获取闲置单元格的时候一致
            cell = [[UITableViewCell alloc] initWithStyle:indexPath.row % 4 reuseIdentifier:identifier];
            //添加右边的图标
            UIImageView *iconView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetWidth(tableView.frame) - 60 - 20, 10, 60, 60)];
            [cell.contentView addSubview:iconView];
            iconView.tag = 101;
            
            //添加左边的标题Label
            UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, CGRectGetWidth(cell.frame) - 100, 60)];
            [cell.contentView addSubview:titleLabel];
            titleLabel.tag = 102;
        }
        
        UIImageView *iconView = [cell.contentView viewWithTag:101];
        UILabel *titleLabel = [cell.contentView viewWithTag:102];
        
        //设置内容
        NSString *iconName = [NSString stringWithFormat:@"icon%ld.jpg",indexPath.row % 6];
        iconView.image = [UIImage imageNamed:iconName];
        
        titleLabel.text = self.datas[indexPath.row];
        
        return cell;
        
    }
  • 相关阅读:
    CCF201503-2数字排序
    CCF201503-1图像旋转
    leetcode 13.罗马数字转整数
    Mysql中limit的用法
    网站访问量统计案例
    ServletContext(重要)
    Servlet(自己实现的Servlet)细节
    HttpServlet
    GenericServlet
    Servlet的相关类--ServletConfig(接口)
  • 原文地址:https://www.cnblogs.com/longiang7510/p/5379183.html
Copyright © 2011-2022 走看看