Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 选中单元格时,在UITableView中显示UIButton_Ios_Iphone_Swift_Uitableview_Uibutton - Fatal编程技术网

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类中实例化该按钮?