2013-08-16 47 views
1

您好我一直在努力擴大細胞從過去幾天從一些互聯網的建議,我發現代碼來擴大customcell。現在我的問題是我在這裏使用自定義單元格,所以擴大單元格後,我想在擴展自定義單元格中添加另一個自定義單元格。所以任何人都可以幫助我做到這一點?在此先感謝在表視圖中如何在ios中的擴展單元中添加另一個自定義單元格?

@interface MyHomeView() 
{ 
    NSIndexPath *selectedindexpath; 

} 
@end 


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    selectedindexpath=indexPath; 

} 

該如何提高我的桌子的高度

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    if(selectedindexpath!=nil &&[selectedindexpath compare:indexPath]==NSOrderedSame) 
    { 

       return 140; 
    } 


    return 52; 

} 
+0

這不是一個簡單的問題,只是重複你之前做過的事情,因爲你已經得到了正確的結果? – geekchic

+0

爲什麼你想在自定義單元格中添加單元格,而不是添加一個完全看起來像表格單元格或不確定的視圖(添加tableview) –

+0

@Shan我想在表格視圖中創建子菜單,所以只有 –

回答

0

這是一個蘋果的示例代碼 Sample code for submenu

此示例代碼展示瞭如何使用的UITableView構建子菜單。基本思想是菜單項將是表格的一部分,子菜單項目將是各個部分的一行。

0

對於該子菜單,請參閱@Iducool發佈的答案。對於你的問題 - >「在表格視圖中如何在ios中的擴展單元中添加另一個自定義單元格?」 這個你最好需要添加其他的UITableView增殖的細胞內,這樣就可以管理它們很容易下面的例子給出了一些主意,把UITableView的自定義的UITableView細胞內

//in your main Table view 

    #import "ViewController.h" 
    #import "CustomCell.h" 
    @interface ViewController()<UITableViewDataSource , UITableViewDelegate> 

    @end 

    @implementation ViewController 

    - (void)viewDidLoad 
{ 
     [super viewDidLoad]; 
     // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)didReceiveMemoryWarning 
    { 
     [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
    } 

    - (void)dealloc 
    { 
    [_aTV release]; 
    [super dealloc]; 
    } 


    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 
     return 1; 
    } 

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
     return 3; 
    } 

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    CustomCell *cell = [self.aTV dequeueReusableCellWithIdentifier:@"Cell"]; 
    if(cell == nil) 
    { 
     cell = [[[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]autorelease]; 
    } 

    cell.dataAraay = [NSMutableArray arrayWithObjects:@"subMenu->1",@"subMenu->2",@"subMenu->3",@"subMenu->4",@"subMenu->5", nil]; 
    return cell; 
    } 

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    return 150; 
    } 


    //in your custom tableview cell 
    // .m file 
    #import "CustomCell.h" 

    @implementation CustomCell 
    @synthesize dataAraay; //array to hold submenu data 

    - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
    { 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
    // Initialization code 
    self.frame = CGRectMake(0, 0, 300, 50); 
    UITableView *subMenuTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain]; //create tableview a 

     subMenuTableView.tag = 100; 
     subMenuTableView.delegate = self; 
     subMenuTableView.dataSource = self; 
     [self addSubview:subMenuTableView]; // add it cell 
     [subMenuTableView release]; // for without ARC 
    } 
    return self; 
} 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
{ 
    [super setSelected:selected animated:animated]; 

     // Configure the view for the selected state 
} 

-(void)layoutSubviews 
    { 
    [super layoutSubviews]; 
    UITableView *subMenuTableView =(UITableView *) [self viewWithTag:100]; 
    subMenuTableView.frame = CGRectMake(0.2, 0.3, self.bounds.size.width-5, self.bounds.size.height-5);//set the frames for tableview 

    } 

//manage datasource and delegate for submenu tableview 
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 
    return 1; 
    } 

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
     return dataAraay.count; 
    } 

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID"]; 
    if(cell == nil) 
     { 
     cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellID"]autorelease]; 
     } 
    cell.textLabel.text = [self.dataAraay objectAtIndex:indexPath.row]; 

    return cell; 

} 

@end 


希望這幫助:)

+0

那麼我會檢查這個和會說你@ shan \ –

+0

我想在menu1-> 3子菜單,menu2->子菜單4以及子菜單1 - >想要添加子子菜單的每個菜單中添加不同的子菜單。所以我要再次重複這個過程是這樣嗎? –

+0

爲此你需要看一看@Iducool的答案 –

相關問題