2017-02-18 5 views
0

Я могу показать editPhotoActionSheet по телефону showActionSheetToEditPhoto().Как показать второй лист действий при нажатии кнопки в первом листе действий, Swift

Когда я нажимаю кнопку удаления в editPhotoActionSheet, я хотел бы показать deletePhotoActionSheet, но я не могу это сделать с помощью приведенного ниже кода. Прошу совета, как я мог бы это достичь.

Также смотрите оба листа действия ниже.

func showActionSheetToEditPhoto() -> UIAlertController { 

    let alertController : UIAlertController = UIAlertController() 
    let takePhoto : UIAlertAction = UIAlertAction(title: "Take Photo", style: .default) { (alert) in 
     print("User pressed Take Photo") 
     self.takePhoto() 
    } 
    let choosePhoto : UIAlertAction = UIAlertAction(title: "Choose Photo", style: .default) { (alert) in 
     print("User pressed Choose Photo") 
     self.choosePhoto() 
    } 
    let editPhoto : UIAlertAction = UIAlertAction(title: "Edit Photo", style: .default) { (alert) in 
     print("User pressed Edit Photo") 
     self.editExisitingProfilePhoto() 
    } 

    let deletePhoto : UIAlertAction = UIAlertAction(title: "Delete Photo", style: .default) { (alert) in 
    print("User pressed Delete Photo") 
    self.showDeletePhotoActionSheet() 

    } 

    let cancel : UIAlertAction = UIAlertAction(title: "Cancel", style: .cancel) { (alert) in 
     print("User pressed Cancel") 
    } 

    alertController.addAction(takePhoto) 
    alertController.addAction(choosePhoto) 
    alertController.addAction(editPhoto) 
    alertController.addAction(deletePhoto) 
    alertController.addAction(cancel) 
    alertController.popoverPresentationController?.sourceView = view 
    alertController.popoverPresentationController?.sourceRect = view.frame 

    return alertController 
} 

func showDeletePhotoActionSheet() -> UIAlertController { 
    print("showOptionsToDeletePhoto function called") 
    self.dismiss(animated: true, completion: nil) // Dismissing previous alert 

    let alertController : UIAlertController = UIAlertController() 
    let deletePhoto : UIAlertAction = UIAlertAction(title: "Delete Photo", style: .default) { (alert) in 
     print("User pressed delete Photo") 
     var existingPhoto = self.profilePhoto.image 
     if existingPhoto != nil{ 
      self.profilePhoto.image = nil 
     } 
    } 

    let cancel : UIAlertAction = UIAlertAction(title: "Cancel", style: .cancel) { (alert) in 
     print("User pressed Cancel") 
    } 

    alertController.addAction(deletePhoto) 
    alertController.addAction(cancel) 
    alertController.popoverPresentationController?.sourceView = view 
    alertController.popoverPresentationController?.sourceRect = view.frame 

    return alertController 
} 

EditPhotoActionSheet

EditPhotoActionSheet

DeletePhotoActionSheet

DeletePhotoActionSheet

ответ

1

Ваш метод showDeletePhotoActionSheet вернуть UIAlertController Insta но вы не использовали этот объект для представления листа действий. Представьте действие action в действии deletePhoto.

let deletePhoto : UIAlertAction = UIAlertAction(title: "Delete Photo", style: .default) { (alert) in 
    print("User pressed Delete Photo") 
    let alert = self.showDeletePhotoActionSheet() 
    //present delete the action sheet 
    self.present(alert, animated: true) //Or self.present(self.showDeletePhotoActionSheet(), animated: true) 
} 
Смежные вопросы