如何快速清除tableview中的现有数据?

时间:2019-07-02 11:31:23

标签: ios swift tableview uiimagepickercontroller

image1image2。我有带表视图的段控制器,当我选择任何单元格时,它会显示图像选择器,一旦选择了图像,它将显示在tableViewCell中。

  1. 当我尝试用上一张更新所选图像时,它会显示多张图像,而不是最新一张。

func tableView(_ tableView: UITableView, numberOfRowsInSection 
    section: Int) -> Int {
       let selectedIndex = SegmentController.selectedSegmentIndex
       switch selectedIndex {
          case 0: return idProof.count
          case 1: return addressProof.count //Add other cases here 
          default: return 0
       }
    }

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomTableviewCell
   cell.selectionStyle = .none
    if SegmentController.selectedSegmentIndex == 0 {
        cell.prooofLable?.text = idProof[indexPath.row]
    } else if SegmentController.selectedSegmentIndex == 1 {
        cell.prooofLable?.text = addressProof[indexPath.row]
    }
    return cell
}

@IBAction func segmentedTapped(_ sender: Any)
{
    if SegmentController.selectedSegmentIndex == 0 || SegmentController.selectedSegmentIndex == 1 {
        Tableview.reloadData()
    }
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
        let path = IndexPath(row: self.selectedCell.row, section: 0)
        let cell = Tableview.cellForRow(at: path) as! CustomTableviewCell
        cell.documentImage?.image  = pickedImage
        cell.documentImage?.clipsToBounds  = true
        cell.documentImage?.contentMode = .scaleToFill
        cell.documentImage?.frame = CGRect()
    }
    Tableview.reloadData()
    picker.dismiss(animated: true, completion: nil)
}

选择图像后,我必须在单元格中显示单个图像(其中任何一个)。

0 个答案:

没有答案