Ios 选中单元格时,在UITableView中显示UIButton
我想在我的Ios 选中单元格时,在UITableView中显示UIButton,ios,iphone,swift,uitableview,uibutton,Ios,Iphone,Swift,Uitableview,Uibutton,我想在我的UITableViewCell中添加一个ui按钮。选中该按钮后,我的单元格会在高度上展开。。只有在展开区域中调用didSelectRow时,才能显示该按钮。。。我有4个单元格,我想用不同的问题、表格和按钮填充它们。我应该对每个单元格进行分类吗 这是我目前的代码: let SelectedCellHeight: CGFloat = 500.0 let UnselectedCellHeight: CGFloat = 44.0 func numberOfSectionsInTableView
UITableViewCell
中添加一个ui按钮
。选中该按钮后,我的单元格会在高度上展开。。只有在展开区域中调用didSelectRow
时,才能显示该按钮。。。我有4个单元格,我想用不同的问题、表格和按钮填充它们。我应该对每个单元格进行分类吗
这是我目前的代码:
let SelectedCellHeight: CGFloat = 500.0
let UnselectedCellHeight: CGFloat = 44.0
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 4
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let logItemCell = tableView.dequeueReusableCellWithIdentifier("LogCell", forIndexPath: indexPath) as! UITableViewCell
}
// Used to expand cell when selected
func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
if let selectedCellIndexPath = selectedCellIndexPath {
if selectedCellIndexPath == indexPath {
return SelectedCellHeight
}
}
return UnselectedCellHeight
}
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
if let selectedCellIndexPath = selectedCellIndexPath {
if selectedCellIndexPath == indexPath {
self.selectedCellIndexPath = nil
} else {
self.selectedCellIndexPath = indexPath
}
} else {
selectedCellIndexPath = indexPath
}
tableView.beginUpdates()
tableView.endUpdates()
}
是的,您应该创建4个具有不同标识符和类的原型单元格,并根据indexPath在“CellForRowatineXpath”中返回所需的原型单元格。您应该对所需的每个单元格进行子类化。当调用
didSelectRow
并展开单元格时,应调用button.hidden=false
我是否应在创建的UITableViewCell类中实例化该按钮?