2017-07-14 83 views
0

在我的應用程序中,我已經完成了擴展表格視圖單元格,同樣需要展開單元格。我正在面臨再次插入擴展單元格的問題。是否可以這樣做?使用擴展的UITablviewcell添加新單元格

//cellForRowAtIndexPath: 

[cell.expandButton addTarget:self action:@selector(expandAction:) forControlEvents:UIControlEventTouchUpInside]; 

if (indexPath.item < [array count] + 1) { 
     NSLog(@"Show one cell」); 

}else{ 

     NSLog(@"Show another cell") 

} 

//Button action 
-(void) expandAction:(UIButton*)sender{ 
    if (indexPath.item < [array count] + 1) { 
     NSLog(@"Show one cell」); 
    }else{ 

     NSLog(@"Show another cell") 

    } 

} 
+0

與出碼如何能夠幫助 –

+0

別的嘗試RATreeview –

+0

@ Anbu.Karthik我需要沒有任何庫來實現。 –

回答

0

你如何生成你的tableView數據?如果您使用的對象數組,然後你可以把它有點像說:

CellItem級撲救細胞狀態

@interface CellItem : NSObject 
@property BOOL isExpanded; 
@end 

您的自定義單元格類。安裝方法定製您的細胞因CellItem對象狀態的對象

@interface ExpandableCell : UITableViewCell 
- (void)setupWith:(CellItem *)cellItem; 
@end 

@implementation ExpandableCell 
- (void)setupWith:(CellItem *)cellItem { 

    if(cellItem.isExpanded) { 
     //Expand your cell 
    } else { 
     //Don't exp and 
    } 
} 
@end 

陣你在哪裏得到的數據爲您的tableView

@property NSArray<CellItem *> *items; 

協議,它定義了電池狀態委託方法。在類中實現這個方法,這也是yourtableView的委託。每當用戶展開/關閉它時,從單元調用此方法。在實現中保存項目數組中的cellItem。

@protocol ExpandableCellDelegate 
- (void)cellDidChangeStateWithCellItem: (CellItem *)cellItem; 
@end 

UITableView單元是可重複使用的,因此每次單元出現在屏幕上時都應該再次自定義它。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    CellItem *cellItem = self.items[indexPath.row]; 
    ExpandableCell *cell = (ExpandableCell *)[tableView dequeueReusableCellWithIdentifier:@"InsertYourCEllID"]; 
    [cell setupWith:cellItem]; 
    return cell; 
}