【发布时间】:2015-10-23 01:14:48
【问题描述】:
我想在我的UITableViewCell 中添加一个UIButton。我的单元格在被选中时会扩展高度。只有在扩展区域中调用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()
}
【问题讨论】:
标签: ios iphone swift uitableview uibutton