2015-10-26 16 views
0

我是swift新手,我有一個包含2個標籤(名稱和說明)和右側按鈕的表格行。點擊按鈕時,我想在描述的底部顯示一些控件。如何增加swift中單元格內按鈕tapp動作的行高度2

我正在使用自調整技術來動態地將行中的內容合適,通過使用以下代碼。

tableView.rowHeight = IUTableViewAutomaticDimension 

我的描述文字是多行(取決於文本1到5)數據顯示在我的表格視圖就好了。但是在按鈕上敲擊的行高不會自動增加。以下是輕按按鈕中的代碼。

lblmoreDescrption.hidden = false 

我使用的Xcode 7迅速2.

感謝

+1

怎麼樣只是重裝電池? – ogres

+0

謝謝@ogres,按鈕操作在我的tableViewCell中處理,我怎樣才能調用tableview的reloadRowsAtIndexPath? –

+1

將代表從外部(您正在創建單元格的位置)設置爲單元格,並且當點擊該按鈕時,調用代表該按鈕的代理,然後重新加載它 – ogres

回答

2

你需要這樣的:

self.tableView.beginUpdates() 
self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic) 
self.tableView.endUpdates() 

哪裏indexPath是要重新加載的單元格的索引路徑。

0

做更改後,試試這個按鈕點擊。您可以將此目標c代碼轉換爲swift。

[self.tableView beginUpdates]; 
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
[self.tableView endUpdates]; 
1

在斯威夫特:

tableView.beginUpdates() 
    tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade) 
    tableView.endUpdates() 
1

首先,請指定標籤按鈕,你必須加入tableView: cellForRowAtIndexpath indexPath:

而在按鈕單擊事件,不喜歡:

@IBAction func buttonClick(sender:UIButton!) { 

    self.tblName.beginUpdates() 
    self.tblName.reloadRowsAtIndexPaths([NSIndexPath(forRow: sender.tag, inSection: 0)]) , withRowAnimation: UITableViewRowAnimation.Fade) 
    self.tblName.endUpdates() 
} 
0

您可以定義一個UIView的內您的控件,您可以對於該視圖的高度限制採取iboutlet。你需要將它設置爲0,並單擊單元格內的Button時,需要將其設置爲適當的高度,然後在indexpath處重新加載該行。

例如。

Iboutlet UIVIEW *viewCustomControls; // This contains your extra controls which you want to show on the button clicked. 
    Iboutlet NSLayoutConstraints *cons_height_viewControl; // This is the constraint outlet for the viewCustomControls Height. 

當你點擊了您的點擊事件裏面的按鈕...

{ 
if (need to expands) 
{ 
     cons_height_viewControl.constants = 100 // To expand, Here is approximate value you can make as you want. 
}else{ 
     cons_height_viewControl.constants = 0 // To collapse 
    } 
self.tableView.beginUpdates() 
self.tableView.reloadRowsAtIndexPaths:(arrIndexPaths withRowAnimation:UITableViewRowAnimation.Fade) 
self.tableView.endUpdates() 
} 
相關問題