日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UITableView cell自定义视图中插入Table实现复杂界面

發布時間:2024/4/14 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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实现复杂界面的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。