0
をshowActionSheetToEditPhoto()
と呼んで表示することができます。最初のアクションシートSwiftのボタンをクリックしたときに2番目のアクションシートを表示する方法
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
DeletePhotoActionSheet