2017-02-07 9 views
0

Swift 3, Xcode 8.2를 사용하고 있습니다. 나는 사용자 정의 Table View Cell (MyCustomCell)을 가지고 있는데, 여기에는 이미지 뷰와 클릭 할 때 카메라가 열리는 버튼이있다. 사용자는 이러한 셀을 더 추가 할 수 있습니다. 사용자가 단추를 클릭하여 사진을 찍은 다음 해당 단추의 해당 이미지보기에 표시되도록 할 수 있습니다.iOS - 선택한 이미지를 적절한 이미지보기 (imagePickerController)에 배치하는 방법

내 문제는 지금은 항상 첫 번째 이미지보기에 나타나지만 다른 이미지보기에는 나타나지 않는다는 것입니다.

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { 
    if let pickedImage : UIImage = info[UIImagePickerControllerOriginalImage] as? UIImage { 
     let scancell = tableView.cellForRow(at: NSIndexPath(row: 0, section: 0) as IndexPath) as! MyCustomCell // it's this line that is wrong 
     scancell.imgView.contentMode = .scaleAspectFit 
     scancell.imgView.image = pickedImage 
     scancell.cameraButton.isHidden = true 
    }; 

    self.dismiss(animated: true, completion: nil) 
} 

나는 힘든 시간 나는 사용자가 클릭 한 사용자 정의 셀에 통과 할 경우 imagePickerController가 호출되는 방식을 이해하는 데 문제가 있습니다.

나는 이런 식으로 뭔가하고 싶은 : cell 어떻게 든 인수에 전달

tableView.cellForRow(at: tableView.indexPath(for: cell)) 

을하지만 난 imagePickerController의 서명이 수정 될 수 있는지 확실하지 않습니다 그렇다면, 어떻게 그것을 정확히 전화 했어?

도움을 주시면 감사하겠습니다. 감사!

답변

1

같은 것을해야한다)를 클릭했습니다.

var Celltag = 0 

    func tableView_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell((withIdentifier: "")) as! MyCustomCell 
    cell.customButton.tag = indexPath.row 
    cell.customButton.addTarget(self, action: #selector(ButtonClickMethod), for: .touchUpInside) 
    return cell 
    } 


    func ButtonClickMethod (sender:UIButton) { 
    Celltag = sender.tag 
    ........ 
    } 

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { 
     if let pickedImage : UIImage = info[UIImagePickerControllerOriginalImage] as? UIImage { 
      let scancell = tableView.cellForRow(at: NSIndexPath(row: Celltag, section: 0) as IndexPath) as! MyCustomCell 
      scancell.imgView.contentMode = .scaleAspectFit 
      scancell.imgView.image = pickedImage 
      scancell.cameraButton.isHidden = true 
     }; 

     self.dismiss(animated: true, completion: nil) 
    } 

희망이 도움이됩니다.

+0

나는 이것을 아주 좋아하지는 않았지만이 대답은 올바른 길을 찾는데 도움이되었다. 고맙습니다! – noblerare

0

귀하의 MyCustomCell 클래스에서 사용자가 하나의 사진을 선택하고 사용자가 선택한 사진을 반환 할 수있는 imagePicker에이 기능이 있어야합니다. 그런 다음 cellForRow를 사용하여 tableViewController 데이터 소스 메소드 (여기에는 셀의 indexPath도 전달) 사용자는 cellForRow 방법에서 버튼에 태그를 추가하고 세포를 얻기 위해 해당 태그를 사용

func tableView_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(...) as! MyCustomCell 
    let image = cell.pickImage 
    cell.image = image 

    return cell 
}