2015-10-26 44 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() 
} 
相关问题