zoukankan      html  css  js  c++  java
  • 自定义cell分方法

    #import <UIKit/UIKit.h>

    @interface Label_TableViewCell : UITableViewCell
    //分别声明 你要创建的UILabel 和  UIIMageView
    /**
     *  图片
     */
    @property (nonatomic,retain)UIImageView *HeadImageView;
    /**
     *  标题
     */
    @property (nonatomic,retain) UILabel  *titleLabel;
    /**
     *  价格
     */
    @property (nonatomic,retain)UILabel *priceLabel;
    /**
     *  评价
     */
    @property(nonatomic,retain)UILabel  *pingjiaLabel;
    @end
     
     

    //     自定义cell(代码)()
    - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
    {
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
       
        if (self) {
           
    //        添加图片
            self.HeadImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
           
    //        当前的视图
            [self.contentView addSubview:self.HeadImageView];
           
    //        添加标题Label
            self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(100+5, 0, 80, 30)];
            self.titleLabel.backgroundColor = [UIColor blueColor];
            [self.contentView addSubview:self.titleLabel];
       
    //        添加价格的Label
            self.priceLabel = [[UILabel alloc]initWithFrame:CGRectMake(100+5, 50, 100, 30)];
            self.priceLabel.backgroundColor = [UIColor orangeColor];
            [self.contentView addSubview:self.priceLabel];
           
    //        添加评价的label
            self.pingjiaLabel = [[UILabel alloc]initWithFrame:CGRectMake(200+60, 0, 80, 30)];
            self.pingjiaLabel.backgroundColor = [UIColor redColor];
            [self.contentView addSubview:self.pingjiaLabel];
     
     
     
    #import "ViewController.h"
    #import "Label_TableViewCell.h"
    #import "Other_ViewController.h"


    @interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
    {
    //    注意在导航栏里面,在进入写一个页面,(必须初始化一个全局变量)
    //   Other_ViewController *other;
    //    定义一个全局变量的数组
        NSArray *list ;
    }

    @end

    @implementation ViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
        [self loadData];
        self.view.backgroundColor = [UIColor grayColor];
       
    //    初始化UITableView
        UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 300,675 )];
        tableView.delegate = self;
        tableView.dataSource = self;
       
    //    试着行高
        tableView.rowHeight = 100;
        [self.view addSubview:tableView];
    }


    //     取出数组
    - (void)loadData
    {
       
    //    取出plist 的数据
        NSString *path = [[NSBundle mainBundle]pathForResource:@"aa" ofType:@"plist"];
        list = [NSArray arrayWithContentsOfFile:path];
    }


    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return 10;
    }

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
      
           Other_ViewController *other = [[Other_ViewController alloc]init];
       
    //    取出字典里面的key值,依次取出
    //    表示的是整个UITableView的所有行
    //    取出数组里面的内容
             other.text = list[indexPath.row][@"a"];
             NSLog(@"%@",other.text);
       
    //    跳回到下一个页面
          [self.navigationController pushViewController:other animated:YES];
    }



    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSString *cellID = @"cellID";
        Label_TableViewCell  *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
       
        if (!cell) {
                cell = [[Label_TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
         }
    //      cell.detailTextLabel.text = @"好好总结";
    //      cell.textLabel.text= @"回忆";
    //      cell.imageView.image = [UIImage imageNamed:@"22.jpg"];
    //     在每一行里面的每一个按钮
        cell.HeadImageView.image = [UIImage imageNamed:@"22.jpg"];
        cell.titleLabel.text = @"记忆";
        cell.pingjiaLabel.text = @"学习";
        cell.priceLabel.text = @"梦痕";

        return cell;
    }
       
  • 相关阅读:
    jquery animate()方法 语法
    jquery unload方法 语法
    jquery undelegate()方法 语法
    jquery unbind()方法 语法
    jquery trigger() 方法 语法
    jquery toggle()方法 语法
    jquery change() 函数 语法
    jquery blur()函数 语法
    jquery bind()方法 语法
    jquery checked选择器 语法
  • 原文地址:https://www.cnblogs.com/wukun16/p/4844751.html
Copyright © 2011-2022 走看看