swift - Cannot call value of non-function type UIAlertAction -
i'm not sure what's wrong function. i'm trying present alert asking if user delete selected photo.
if function deletes photo returns error, show error user.
xcode failing on errorcontroller.addaction line message "cannot call value of non-function type uialertaction"
i'm using swift 2
@ibaction func deletephoto(sender: anyobject) { let alertcontroller = uialertcontroller(title: "delete photo", message: "are sure want delete photo?", preferredstyle: .alert) let okaction = uialertaction(title: "ok", style: .default) { uialertaction in self.photogateway!.delete(self.photo!.id!, completion: { (witherror: bool) -> void in if (witherror == true) { let errorcontroller = uialertcontroller(title: "delete failed", message: "blah", preferredstyle: uialertcontrollerstyle.alert) // next line causing error errorcontroller.addaction(uialertaction(title: "ok", style: uialertactionstyle.default, handler: nil)) self.presentviewcontroller(errorcontroller, animated: true, completion: nil) } else { self.dismissviewcontrolleranimated(true, completion: nil) } }) } let cancelaction = uialertaction(title: "cancel", style: .cancel) { uialertaction in print("cancelled") } alertcontroller.addaction(okaction) alertcontroller.addaction(cancelaction) self.presentviewcontroller(alertcontroller, animated: true, completion: nil) }
if take out offending line works well, user has no way of dismissing alert
fixed it. changed:
errorcontroller.addaction(uialertaction(title: "ok", style: uialertactionstyle.default, handler: nil))
to:
errorcontroller.addaction(uikit.uialertaction(title: "ok", style: uialertactionstyle.default, handler: nil))
Comments
Post a Comment