UITableView cell自定义视图中插入Table实现复杂界面
生活随笔
收集整理的這篇文章主要介紹了
UITableView cell自定义视图中插入Table实现复杂界面
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
最近項(xiàng)目中需要實(shí)現(xiàn)如下圖所示的效果:
通過(guò)界面我們斷定是一個(gè)UITableView,分成三部分,第一部分是全天,第二部分是上午,第三部分是下午。最主要的是AM和PM中也是列表,這個(gè)就比較復(fù)雜了。我的做法是在Iphone在table cell中添加自定義布局view這篇文章的基礎(chǔ)上制作更復(fù)雜的界面。具體的過(guò)程如下:
?
- 創(chuàng)建UITableViewCell的自定義類(lèi),這個(gè)就不用說(shuō)了,在之前的博客中介紹過(guò)。
- 在創(chuàng)建的cell中添加一個(gè)新的UITableView。
?????????
代碼 在自定義的cell中添加組建,我的類(lèi)是MyProfileTableViewCell,在這個(gè)中添加:IBOutlet UITableView *myTaleView;
IBOutlet UILabel *lable;
實(shí)現(xiàn)相應(yīng)的set get方法。在和IB中相應(yīng)的組建相連。
在tableview中引入相應(yīng)的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;
}
}
在相應(yīng)的cell中添加UITableView相應(yīng)的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
在添加相應(yīng)的協(xié)議函數(shù)即可:
#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:@"早上起來(lái)賣(mài)大米,賣(mài)了一筐大大米。\n早上起來(lái)賣(mài)大米,賣(mài)了一筐大大米。"];
return cell;
}
- (CGFloat)tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 56;
}
@end
轉(zhuǎn)載于:https://www.cnblogs.com/lm3515/archive/2010/12/17/1908956.html
總結(jié)
以上是生活随笔為你收集整理的UITableView cell自定义视图中插入Table实现复杂界面的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 为netbean配置C++编译环境
- 下一篇: 通过C++ Interop把Window