我可以通过调用editPhotoActionSheet
来显示showActionSheetToEditPhoto()
。
当我点击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
答案 0 :(得分:1)
您的方法showDeletePhotoActionSheet
返回UIAlertController
个实例,但您尚未使用该对象来显示操作表。因此,请在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)
}