2015-09-01 35 views

回答

0
  1. 創建包含數組所選單元格指數的

    var selectedCellIndexs : NSMutableArray = [] 
    
  2. 在didSelectRowAtIndexPath方法indexPath:NSIndexPath)函數add:

    self.selectedCellIndexs.addObject(indexPath) 
    tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) 
    
  3. 現在在的tableView(的tableView:UITableView的, heightForRowAtIndexPath indexPath:NSIndexPath),你需要做的就是檢查單元格是否是選定數組的一部分,如果它返回一個不同的v ALUE。

    if (self.selectedCellIndexs.containsObject(indexPath)) { 
        return selectedHeight 
    } 
    return notSelectedHeight 
    
  4. ,如果你想取消你需要單擊單元格時,從您的selectedCellIndexs刪除索引路徑的細胞記住了這一點。

注意:這是用戶選擇單元格更改高度時的基本工作流程。需要更多的工作才能從按鈕操作中獲取單元格。

+0

這項工作對我很好!謝謝大家 – aotian16

0

您應該將所有tableviewcell的高度存儲在NSMutableArray中。

當用戶點擊tableviewcell的按鈕時,更新heightNSMutableArray

之後reload你的UITableView

希望這會有所幫助。

0

全局聲明一個mutableArray。

var buttonPressedIndexPaths : NSMutableArray = [] 

cellForRowAtIndexPath()方法

cell?.button.tag = indexPath.row 
cell?.button.addTarget(self, action: "onButtonAction:", forControlEvents: UIControlEvents.TouchUpInside) 

複製粘貼這些方法

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat 
{ 
     if(buttonPressedIndexPaths.containsObject(indexPath)) 
     { 
     return 90;//button pressed cell height 
    } 
    else 
     { 
     return 44;//normal 
    } 
} 

func onButtonAction(sender:UIButton) 
{ 
    var indexPath : NSIndexPath = NSIndexPath(forRow: sender.tag, inSection: 0)//section may differ based on ur requirement 
    if(buttonPressedIndexPaths.containsObject(indexPath)) 
    { 
     buttonPressedIndexPaths.removeObject(indexPath) 
    } 
    else 
    { 
     buttonPressedIndexPaths.addObject(indexPath) 
    } 
    tableView.reloadData(); 
} 
相關問題