zoukankan      html  css  js  c++  java
  • 自己的自定义单元格(IOS)

    定义自己的单位格有三种方法

    - 代码

    - xib

    - storyboard(推荐)

    操作方法故事板

    1、在TableView财产Prototype Cells至1。莫感觉1;

    2、须要创建自己定义的单元格类;

    3、设定Table View Cell的Class为自己定义类;


    自己定义类:(并不难)

    #import "CustomCell.h"
    
    @implementation CustomCell
    
    - (void)awakeFromNib {
        // Initialization code
    }
    
    - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
        [super setSelected:selected animated:animated];
    
        // Configure the view for the selected state
    }
    
    @end
    




    必须实现的数据源协议的方法:

    #pragma mark --UITableViewDataSource 协议方法
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return [self.listTeams count];
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // 定义可重用单元格对象
        static NSString *cellIdentifier = @"Cell";
        CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        
        NSUInteger row = [indexPath row];
        NSDictionary *rowDict = [self.listTeams objectAtIndex:row];
        cell.name.text = [rowDict objectForKey:@"name"];
     
        NSString *imagePath = [rowDict objectForKey:@"image"];
        imagePath = [imagePath stringByAppendingString:@".png"];
        cell.image.image = [UIImage imageNamed:imagePath];
        
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return cell;
    }


    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    移动web技能总结
    canvas绘图基础
    如何自定义滚动条?
    学习笔记-AngularJs(十)
    学习笔记-AngularJs(九)
    硬盘杀手!Windows版Redis疯狂占用C盘空间【转】
    64位win10系统无法安装.Net framework3.5的两种解决方法【转】
    分享一个电子书地址
    阿里、腾讯、百度、华为、京东、搜狗和滴滴最新面试题汇集【转】
    jQuery时间轴
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/4650180.html
Copyright © 2011-2022 走看看