利用storyboard 自定义cell
2015-11-02 16:06
218 查看
现在讲究的是快速开发,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呢?
![](http://img.blog.csdn.net/20151102160448952?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
通过这几个步骤就可以成功啦。
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呢?
通过这几个步骤就可以成功啦。
相关文章推荐
- Oracle数据库ORA-01940: 无法删除当前已连接的用户
- TibetanFont | ཡིག་གཟུགས། | 藏文字体
- 第4周实践项目1-- 建立单链表
- 数据结构实践——稀疏矩阵的三元组表示
- CentOS更改yum源与更新系统
- MyBatis(二)--对MySQL数据表进行CRUD操作
- DirectionalViewPager支持横向和纵向的ViewPager
- Eclipse移植项目时JDK版本不匹配Project facet Java version 1.7 is not supported
- 【SQL Server数据迁移】把csv文件中的数据导入SQL Server的方法
- Android LayoutAnimation使用及扩展
- 在同一个jsp页面包括嵌套页面出现2个相同的id会怎么样
- Oracle与DB2数据存储模式的区别详解
- 在android项目中使用FontAwesome字体
- WebApi传参总动员(五)
- url操作等
- 第九周项目3——稀疏矩阵的三元组表示的实现及应用(2)
- Android数据业务发起流程(原)
- Android 插件平台技术 <一> 基本介绍和dynamic-load-apk介绍
- 猴子选大王(数组版)
- 钛资本:大众创业时代,咨询行业也要被颠覆