我这里有这个问题。
我在我正在使用的库中找到了这个类public class ImageSlideshowItem: UIScrollView, UIScrollViewDelegate {
。
所以我想在scrollView
中添加一个alertController,但是使用这段代码我得到一个错误
func saveImage() {
UIImageWriteToSavedPhotosAlbum(self.imageView.image!, self, "image:didFinishSavingWithError:contextInfo:", nil)
}
func image(image: UIImage!, didFinishSavingWithError error: NSError!, contextInfo: AnyObject!) {
if (error != nil) {
// Something wrong happened.
print("not saved")
} else {
// Everything is alright.
let alert = UIAlertController(title: "My Title", message: "This is my message.", preferredStyle: UIAlertControllerStyle.Alert)
// add an action (button)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
var fullscree: FullScreenSlideshowViewController = FullScreenSlideshowViewController()
// show the alert
self.presentViewController(alert, animated: true, completion: nil)
}
}
错误就是这个。
类型的价值' ImageSlideshowItem'没有会员' presentViewController'
如何知道如何显示警报?
更新
这是我称之为ImageSlideshowItems
的另一个类的链接这是完整的ImageSlideShowItem类
答案 0 :(得分:1)
您遇到的问题是ScrollView
是UIView
对象的类型而不是controller
,因此您没有presentViewController
在ScrollView
的子类中UIViewController
1}},为了解决你可以这样尝试的问题,在该类中创建一个scrollView
实例,并在任何{{1时使用该实例初始化ViewController
时使用该实例来呈现alertController ,只需传递viewController
的引用,就像这样
public class ImageSlideshowItem: UIScrollView, UIScrollViewDelegate {
var viewController: UIViewController?
func image(image: UIImage!, didFinishSavingWithError error: NSError!, contextInfo: AnyObject!) {
if (error != nil) {
// Something wrong happened.
print("not saved")
} else {
// Everything is alright.
let alert = UIAlertController(title: "My Title", message: "This is my message.", preferredStyle: UIAlertControllerStyle.Alert)
// add an action (button)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
var fullscree: FullScreenSlideshowViewController = FullScreenSlideshowViewController()
// show the alert
self.viewController?.presentViewController(alert, animated: true, completion: nil)
}
}
}
现在使用您的scrollView
对象传递当前ViewController的实例。
let imgslider = ImageSlideshowItem()
imgslider.viewController = self