利用storyboard 自定义cell

11 篇文章 0 订阅
7 篇文章 0 订阅
这篇博客介绍了如何在iOS开发中利用Storyboard快速自定义UITableViewCell,通过创建自定义cell类并设置IBOutlet,结合UITableViewDataSource方法实现内容的显示。
摘要由CSDN通过智能技术生成

现在讲究的是快速开发,storyboa'r'd自定义cell还是比较少用得,但是开发起来特别快。镔哥就不多说了,直接给你们demo看吧

1:自定义cell

//  xdxTableViewCell.h

//  短线狙击

//

//  Created by taogu on 15/10/28.

//  Copyright © 2015 com.taogucn.www. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface xdxTableViewCell : UITableViewCell

@property (strong, nonatomic) IBOutlet UILabel *xdxTitle;

@property (strong, nonatomic) IBOutlet UIImageView *isBuy;

@property (strong, nonatomic) IBOutlet UILabel *xdxName;

@property (strong, nonatomic) IBOutlet UILabel *xdxDate;


@end

//

//  xdxTableViewCell.m

//  短线狙击

//

//  Created by taogu on 15/10/28.

//  Copyright © 2015 com.taogucn.www. All rights reserved.

//


#import "xdxTableViewCell.h"


@implementation xdxTableViewCell


- (void)awakeFromNib {

    // Initialization code

}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];


    // Configure the view for the selected state

}


@end


主要文件应用:

//

//  ViewController.h

//  短线狙击

//

//  Created by taogu on 15/10/28.

//  Copyright © 2015 com.taogucn.www. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface ViewController : UIViewController

@property (strong, nonatomic) IBOutlet UITableView *xdxTableView;



@end


//

//  ViewController.m

//  短线狙击

//

//  Created by taogu on 15/10/28.

//  Copyright © 2015 com.taogucn.www. All rights reserved.

//


#import "ViewController.h"

#import "xdxTableViewCell.h"


@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    self.title =@"新短线狙击";

    self.xdxTableView.delegate = self;

    self.xdxTableView.dataSource = self;

     self.xdxTableView.tableFooterView = [[UIView alloc] init];

    // Do any additional setup after loading the view, typically from a nib.

}




#pragma mark - UITabelViewDatasource

- ( CGFloat )tableView:( UITableView *)tableView heightForHeaderInSection:( NSInteger )section


{

    

    return 12.0 ;

    

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return  10;

}


-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    

    xdxTableViewCell *cell = (xdxTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"xdxTableViewCell"];

//    if (_dataArray.count) {

//        cell.contentLabel.text=[[_dataArray objectAtIndex:indexPath.row] objectForKey:@"title"];

//        

//        NSDate * date = [NSDate dateWithTimeIntervalSince1970:[[[_dataArray objectAtIndex:indexPath.row] objectForKey:@"addTime"] longLongValue] ];

//        NSDateFormatter * formatter = [[NSDateFormatter alloc] init];

//        [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];

//        NSString * str = [NSString stringWithFormat:@"%@", [formatter stringFromDate:date]];

//        

//        cell.timeLabel.text =str;

//        [_userDefault setObject:str forKey:@"jueduiTime"];

//        

//        NSString *imageStr =[[_dataArray objectAtIndex:indexPath.row] objectForKey:@"imageUrl"];//图片

//        [cell.neicanImageView setImageWithURL:[NSURL URLWithString:imageStr] placeholderImage:[UIImage imageNamed:@"huodong.png"]] ;

//        

//    }

    

    

    return cell;

    

}


到目前为止你或许还有疑问究竟怎么关联起来storybook建立自定义cell呢?

通过这几个步骤就可以成功啦。





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值