Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.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 当图像单元格崩溃时,如何更改它?_Ios_Swift_Xcode_Uitableview - Fatal编程技术网

Ios 当图像单元格崩溃时,如何更改它?

Ios 当图像单元格崩溃时,如何更改它?,ios,swift,xcode,uitableview,Ios,Swift,Xcode,Uitableview,当我按下单元格并折叠它时,我希望单元格中的图标改变它的位置 以下是表视图的代码: func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! TableViewCell

当我按下单元格并折叠它时,我希望单元格中的图标改变它的位置

以下是表视图的代码:

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! TableViewCell

            cell.serviciosLabel.text! = nameArr[indexPath.row]
            cell.serviciosImageView.image = UIImage(named: "\(imageArr[indexPath.row])")



        /* if (indexPath.row == 2){
         cell.serviciosExpandableView.image = UIImage(named: "\(imgcoll)")

         }

         */


        return cell
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        if indexPath.row == 0 {
            pushVentasTab() // pushVentaArticulos()
        } else if indexPath.row == 1 {
            pushReporteDDia()
        } else if indexPath.row == 2 {
            if SelectedIndex == indexPath.row
            {

                if self.isCollapce == false
                {
                    self.isCollapce = true

                }else
                {
                    self.isCollapce = false
                }
            }else{
                self.isCollapce = true
            }
        }
        self.SelectedIndex = indexPath.row
        tableView.reloadRows(at: [indexPath], with: .automatic)
    }
}

我不知道如何更改它,请看一看并帮助我

,以下是您必须做的。 为TableViewCell创建swift文件,并使用IB将按钮和标签连接到代码

在tableCell swift文件中,声明一个变量iconExpanded

var iconExpanded: Bool = false {
  didSet {
     setupCell()
   }
}
在setupCell()中,具有更改按钮图像的逻辑

func setupCell(){
     if (iconExpanded) {
        // set the image to expanded
     } else {
       // set the image to closed
     }
}
每当表格视图中发生更改时,为特定单元格设置折叠或展开的值,并重新加载特定部分

let sections = IndexSet.init(integer: 0)
tableView.reloadSections(sections, with: .automatic)
最后,将按钮状态的更改发送到单元格

   func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! TableViewCell

            cell.serviciosLabel.text! = nameArr[indexPath.row]
            cell.serviciosImageView.image = UIImage(named: "\(imageArr[indexPath.row])")
            cell.iconExpanded = <true for expand // false for collapse>  
        return cell
    }
func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{
将cell=tableView.dequeueReusableCell(标识符为“cell”)设为!TableViewCell
cell.serviciosLabel.text!=nameArr[indexPath.row]
cell.serviciosImageView.image=UIImage(名称:“\(imageArr[indexPath.row]))
cell.iconExpanded=
返回单元
}

nameArr是一个数组,创建一个结构来存储每个单元格的名称和展开状态。

谢谢@Shubhamhappy的帮助:)@JesusLoaizaHerrera