close

UITableView cell自訂視圖中插入Table實現複雜介面

from http://fecbob.pixnet.net/blog/post/35423964

最近專案中需要實現如下圖所示的效果:
image_thumb8.png  

通過介面我們斷定是一個UITableView,分成三部分,第一部分是全天,第二部分是上午,第三部分是下午。最主要的是AM和PM中也是清單,這個就比較複雜了。我的做法是在Iphone在table cell中添加自訂佈局view這篇文章的基礎上製作更複雜的介面。具體的過程如下:




•創建UITableViewCell的自訂類,這個就不用說了,在之前的博客仲介紹過。
•在創建的cell中添加一個新的UITableView。

image_thumb9.png  

在自訂的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 * 細胞 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier] ;
如果 (儲存格 = = 零) {
儲存格 = [[[UITableViewCell 分配] initWithStyle:UITableViewCellSelectionStyleGray
reuseIdentifier:CellIdentifier] autorelease] ;
}
返回儲存格 ;
} {其他
MyProfileTableViewCell * 細胞 = (MyProfileTableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier] ;
NSArray * 陣列 = [[NSBundle mainBundle] loadNibNamed:@"MyProfileTableViewCell"所有者: 自選項: 零] ;
儲存格 = [陣列 objectAtIndex:0] ;
[細胞 setSelectionStyle:UITableViewCellSelectionStyleGray] ;
如果 ([indexPath 節] = = 1) {
[[儲存格標籤] setText:@"AM"] ;
}
如果 ([indexPath 節] = = 2) {
[[儲存格標籤] setText:@"PM"] ;
}
返回儲存格 ;
}
}

 

•在相應的cell中添加UITableView相應的Delegate和DataSource,我的cell完整的聲明如下:
# import <UIKit/UIKit.h>
@ 介面 MyProfileTableViewCell: UITableViewCell
< UITableViewDelegate,UITableViewDataSource > {
IBOutlet UITableView * myTaleView ;
IBOutlet UILabel * 標籤 ;
}
@ 屬性 (非原子,保留) UITableView * myTaleView ;
@ 屬性 (非原子,保留) UILabel * 標籤 ;
@ 結束

 

•在添加相應的協定函數即可:
# import"MyProfileTableViewCell.h"
# import"MyTableViewCell.h"
實施 MyProfileTableViewCell @
@ 合成 myTaleView,標籤 ;
-(id) initWithStyle: (UITableViewCellStyle) 樣式 reuseIdentifier:(NSString *) reuseIdentifier {
如果 ((自我 = [超級 initWithStyle:style reuseIdentifier:reuseIdentifier])) {
}
返回自 ;
}
-(失效) setSelected: (BOOL) 選擇動畫: (BOOL) 動畫 {
[超級 setSelected: 選定動畫: 動畫] ;
}
-(失效) dealloc {
[self.lable 發佈] ;
[self.myTaleView 發佈] ;
[超級 dealloc] ;
}
-(NSInteger) tableView:(UITableView *) tableView1 numberOfRowsInSection: (NSInteger) 節 {
返回 5 ;
}
-(UITableViewCell *) tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath {
靜態 NSString * CellIdentifier ="CustomCellIdentifier"; @
MyTableViewCell * 細胞 = (MyTableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier] ;
如果 (儲存格 = = 零) {
NSArray * 陣列 = [[NSBundle mainBundle] loadNibNamed:@"MyTableViewCell"所有者: 自選項: 零] ;
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

 

我在這裡又添加了一個子cell,效果和之前的一樣。

 

下麵在總結一下實現的過程,就是在一個tableview中的cell中在添加一個uitableview。
arrow
arrow
    全站熱搜

    zer931 發表在 痞客邦 留言(0) 人氣()