Ios 如何在swift 2中增加单元格内按钮tapp动作的行高
我是swift新手,我有一个包含2个标签(名称和描述)的表行,右侧有一个按钮。单击按钮后,我想在“说明”底部显示一些控件 我正在使用自调整大小技术,通过使用以下代码动态调整行中的内容Ios 如何在swift 2中增加单元格内按钮tapp动作的行高,ios,uitableview,swift2,xcode7,Ios,Uitableview,Swift2,Xcode7,我是swift新手,我有一个包含2个标签(名称和描述)的表行,右侧有一个按钮。单击按钮后,我想在“说明”底部显示一些控件 我正在使用自调整大小技术,通过使用以下代码动态调整行中的内容 tableView.rowHeight = IUTableViewAutomaticDimension 我的描述文本是多行的(取决于文本1到5),数据在我的表视图中显示得很好。但在按钮上点击的行高度并没有自动增加。以下是点击按钮中的代码 lblmoreDescrption.hidden = false 我将Xc
tableView.rowHeight = IUTableViewAutomaticDimension
我的描述文本是多行的(取决于文本1到5),数据在我的表视图中显示得很好。但在按钮上点击的行高度并没有自动增加。以下是点击按钮中的代码
lblmoreDescrption.hidden = false
我将Xcode 7与swift 2配合使用
谢谢在进行更改后,请尝试此按钮并单击。您可以将此目标c代码转换为swift
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
在进行更改后,单击按钮尝试此操作。您可以将此目标c代码转换为swift
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
迅速:
tableView.beginUpdates()
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade)
tableView.endUpdates()
迅速:
tableView.beginUpdates()
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade)
tableView.endUpdates()
你需要这个:
self.tableView.beginUpdates()
self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
self.tableView.endUpdates()
其中indexPath
是要重新加载的单元格的索引路径。您需要:
self.tableView.beginUpdates()
self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
self.tableView.endUpdates()
其中,
indexath
是您要重新加载的单元格的索引路径。首先,请将标签分配给您在tableView:cellForRowAtIndexpath:
在按钮单击事件中,执行以下操作:
@IBAction func buttonClick(sender:UIButton!) {
self.tblName.beginUpdates()
self.tblName.reloadRowsAtIndexPaths([NSIndexPath(forRow: sender.tag, inSection: 0)]) , withRowAnimation: UITableViewRowAnimation.Fade)
self.tblName.endUpdates()
}
首先,请将标签分配给您在
tableView:cellforrowatinexpath indexath:
在按钮单击事件中,执行以下操作:
@IBAction func buttonClick(sender:UIButton!) {
self.tblName.beginUpdates()
self.tblName.reloadRowsAtIndexPaths([NSIndexPath(forRow: sender.tag, inSection: 0)]) , withRowAnimation: UITableViewRowAnimation.Fade)
self.tblName.endUpdates()
}
您可以在一个UIView中定义控件,并且可以将iboutlet作为该UIView的高度约束。您需要将其设置为0作为Previor,当单击单元格内的按钮时,需要将其设置为适当的高度,然后在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()
}
您可以在一个UIView中定义控件,并且可以将iboutlet作为该UIView的高度约束。您需要将其设置为0作为Previor,当单击单元格内的按钮时,需要将其设置为适当的高度,然后在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()
}
重新加载单元格怎么样?谢谢@ogres,按钮操作在我的tableViewCell内部处理。我如何调用tableview的reloadRowsAtIndexPath?从外部(创建单元格的地方)将委托设置为单元格当按钮被点击时,给被点击的代表打电话,然后重新加载它。这就是我想做的。但是还有其他合适的/默认的方法吗?这是合适的方法。重新加载单元格怎么样?谢谢@ogres,按钮操作在我的tableViewCell内部处理。我如何调用tableview的重新加载RowsatindeXPath?从外部(创建单元格的地方)将委托设置为单元格当按钮被点击时,给被点击的代表打电话,然后重新加载它。这就是我想做的。但是还有其他合适的/默认的方法吗?这是合适的方法