UITableView cell自定义视图中插入Table实现复杂界面
生活随笔
收集整理的這篇文章主要介紹了
UITableView cell自定义视图中插入Table实现复杂界面
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近項目中需要實現如下圖所示的效果:
通過界面我們斷定是一個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
轉載于:https://www.cnblogs.com/lm3515/archive/2010/12/17/1908956.html
總結
以上是生活随笔為你收集整理的UITableView cell自定义视图中插入Table实现复杂界面的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 为netbean配置C++编译环境
- 下一篇: 研究UEVENT相关东西,看到2篇优秀的