UITableView cell自定义视图中插入Table实现复杂界面
2013-07-30 15:21
507 查看
最近项目中需要实现如下图所示的效果:
通过界面我们断定是一个UITableView,分成三部分,第一部分是全天,第二部分是上午,第三部分是下午。最主要的是AM和PM中也是列表,这个就比较复杂了。我的做法是在Iphone在table cell中添加自定义布局view这篇文章的基础上制作更复杂的界面。具体的过程如下:
创建UITableViewCell的自定义类,这个就不用说了,在之前的博客中介绍过。
在创建的cell中添加一个新的UITableView。
在自定义的cell中添加组建,我的类是MyProfileTableViewCell,在这个中添加:
IBOutlet UITableView *myTaleView;
IBOutlet UILabel *lable;
实现相应的set get方法。在和IB中相应的组建相连。
在tableview中引入相应的cell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CustomCellIdentifier";
if ([indexPath section]==0) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellSelectionStyleGray
reuseIdentifier:CellIdentifier] autorelease];
}
return cell;
}else {
MyProfileTableViewCell *cell = (MyProfileTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"MyProfileTableViewCell" owner:self options:nil];
cell = [array objectAtIndex:0];
[cell setSelectionStyle:UITableViewCellSelectionStyleGray];
if ([indexPath section]==1) {
[[cell lable] setText:@"AM"];
}
if ([indexPath section]==2) {
[[cell lable] setText:@"PM"];
}
return cell;
}
}
在相应的cell中添加UITableView相应的Delegate和DataSource,我的cell完整的声明如下:
#import <UIKit/UIKit.h>
@interface MyProfileTableViewCell : UITableViewCell
<UITableViewDelegate,UITableViewDataSource>{
IBOutlet UITableView *myTaleView;
IBOutlet UILabel *lable;
}
@property (nonatomic,retain) UITableView *myTaleView;
@property (nonatomic,retain) UILabel *lable;
@end
在添加相应的协议函数即可:
#import "MyProfileTableViewCell.h"
#import "MyTableViewCell.h"
@implementation MyProfileTableViewCell
@synthesize myTaleView,lable;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
- (void)dealloc {
[self.lable release];
[self.myTaleView release];
[super dealloc];
}
- (NSInteger)tableView:(UITableView *)tableView1 numberOfRowsInSection:(NSInteger)section {
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CustomCellIdentifier";
MyTableViewCell *cell = (MyTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"MyTableViewCell" owner:self options:nil];
cell = [array objectAtIndex:0];
[cell setSelectionStyle:UITableViewCellSelectionStyleGray];
}
[[cell label] setText:@"10:00"];
[[cell _content] setText:@"早上起来卖大米,卖了一筐大大米。\n早上起来卖大米,卖了一筐大大米。"];
return cell;
}
- (CGFloat)tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 56;
}
@end
做项目的时候会用的这种情况,把找到的资料再次分享给大家,传播技术人人有责。
通过界面我们断定是一个UITableView,分成三部分,第一部分是全天,第二部分是上午,第三部分是下午。最主要的是AM和PM中也是列表,这个就比较复杂了。我的做法是在Iphone在table cell中添加自定义布局view这篇文章的基础上制作更复杂的界面。具体的过程如下:
创建UITableViewCell的自定义类,这个就不用说了,在之前的博客中介绍过。
在创建的cell中添加一个新的UITableView。
在自定义的cell中添加组建,我的类是MyProfileTableViewCell,在这个中添加:
IBOutlet UITableView *myTaleView;
IBOutlet UILabel *lable;
实现相应的set get方法。在和IB中相应的组建相连。
在tableview中引入相应的cell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CustomCellIdentifier";
if ([indexPath section]==0) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellSelectionStyleGray
reuseIdentifier:CellIdentifier] autorelease];
}
return cell;
}else {
MyProfileTableViewCell *cell = (MyProfileTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"MyProfileTableViewCell" owner:self options:nil];
cell = [array objectAtIndex:0];
[cell setSelectionStyle:UITableViewCellSelectionStyleGray];
if ([indexPath section]==1) {
[[cell lable] setText:@"AM"];
}
if ([indexPath section]==2) {
[[cell lable] setText:@"PM"];
}
return cell;
}
}
在相应的cell中添加UITableView相应的Delegate和DataSource,我的cell完整的声明如下:
#import <UIKit/UIKit.h>
@interface MyProfileTableViewCell : UITableViewCell
<UITableViewDelegate,UITableViewDataSource>{
IBOutlet UITableView *myTaleView;
IBOutlet UILabel *lable;
}
@property (nonatomic,retain) UITableView *myTaleView;
@property (nonatomic,retain) UILabel *lable;
@end
在添加相应的协议函数即可:
#import "MyProfileTableViewCell.h"
#import "MyTableViewCell.h"
@implementation MyProfileTableViewCell
@synthesize myTaleView,lable;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
- (void)dealloc {
[self.lable release];
[self.myTaleView release];
[super dealloc];
}
- (NSInteger)tableView:(UITableView *)tableView1 numberOfRowsInSection:(NSInteger)section {
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CustomCellIdentifier";
MyTableViewCell *cell = (MyTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"MyTableViewCell" owner:self options:nil];
cell = [array objectAtIndex:0];
[cell setSelectionStyle:UITableViewCellSelectionStyleGray];
}
[[cell label] setText:@"10:00"];
[[cell _content] setText:@"早上起来卖大米,卖了一筐大大米。\n早上起来卖大米,卖了一筐大大米。"];
return cell;
}
- (CGFloat)tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 56;
}
@end
做项目的时候会用的这种情况,把找到的资料再次分享给大家,传播技术人人有责。
相关文章推荐
- UITableView cell自定义视图中插入Table实现复杂界面
- UITableView cell自定义视图中实现复杂界面
- UITableView cell自定义视图中插入…
- UITableView cell自定义视图中插入UITableView
- UITableView cell自定义视图中插入Table实现复杂界面
- IOS之UITableView cell自定义视图中插入Tableview
- 一. 使用代码实现UITableView的cell自定义高度-类似于微博主页
- UI学习笔记---第十一天UITableView表视图高级-自定义cell
- UITableView实现选择框和编辑状态时cell向右移动的自定义方法
- iOS UITableView表视图(3)自定义cell
- UITableView实现选择框和编辑状态时cell向右移动的自定义方法
- AutoLayout自定义tableViewCell --- Masonry + UITableView+FDTemplateLayoutCell 纯代码实现
- iOS开发中实现UITableView的Cell左划删除等自定义功能
- ios TableView那些事(三十 五)TableView 单选操作使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- 自定义带网络请求的UITableView中tableHeaderView视图
- qt利用委托:QStyledItemDelegate,实现tableview 的表格项的自定义显示,如插入图片,绘制控件
- TableView中实现自定义cell
- iOS UITableView(四) 为tableView设置头尾视图,改变cell的宽度,cell的缩进
- 自定义UITableView,实现cell的三级分组展开收起
- 在一个tableView 中需要自定义多种样式的cell(两种或三种),通常你如何实现,说说思路即可?