如何在swift 2中的单元格内的按钮tapp操作上增加行高

时间:2015-10-26 11:03:12

标签: ios uitableview swift2 xcode7

我是swift的新手,我有一个包含2个标签(名称和描述)的表格行和一个右侧的按钮。点击按钮我想在描述底部显示一些控件。

我正在使用自我调整技术,通过使用以下代码动态调整行中的内容。

tableView.rowHeight = IUTableViewAutomaticDimension

我的描述文字是多行的(取决于文本1到5)数据显示在我的表视图中就好了。但是按钮上的行高不会自动增加。以下是按下按钮的代码。

lblmoreDescrption.hidden = false

我正在使用Xcode 7和swift 2.

由于

5 个答案:

答案 0 :(得分:3)

你需要这个:

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

其中indexPath是您要重新加载的单元格的索引路径。

答案 1 :(得分:1)

在斯威夫特:

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

答案 2 :(得分: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()
}

答案 3 :(得分:0)

执行更改后,在按钮单击时尝试此操作。您可以将此目标c代码转换为swift。

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

答案 4 :(得分:0)

您可以在一个UIView中定义控件,并且可以为该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()
}