在Swift imageview控制器中需要帮助到另一个视图控制器

时间:2015-04-08 07:10:44

标签: ios swift uiview

  @IBAction func savePicture(sender: AnyObject) {

        UIGraphicsBeginImageContextWithOptions(mainImageView.frame.size,false,0.0)
        mainImageView.layer.renderInContext(UIGraphicsGetCurrentContext())
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()

        let alert = SCLAlertView()

        alert.addButton("YES", action: {
            UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil)
            //Save pop success tips
            let alert1 = SCLAlertView()
            alert1.showSuccess(self, title: "Saved successfully", subTitle: "^_^", closeButtonTitle: "OK", duration: 0)

            //I want to link to another View controller
        })

        alert.showInfo(self, title: "Okay to save?", subTitle: "Pictures will be saved to the album", closeButtonTitle: "NO", duration: 0)
       }

我需要在将图片成功保存到照片库后链接到另一个 TableViewController

**我尝试过使用此代码,但它不起作用

 var VC1 = self.storyboard?.instantiateViewControllerWithIdentifier("MyViewController") as ViewController
            let navController = UINavigationController(rootViewController: VC1) // Creating a navigation controller with VC1 at the root of the navigation stack.
            self.presentViewController(navController, animated:true, completion: nil)

请帮助我谢谢!!

1 个答案:

答案 0 :(得分:0)

你的逻辑被打破了。 UIImageWriteToSavedPhotosAlbum也可能失败,因此存在completionTargetcompletionSelector。你应该检查一下。

因为您确实使用了Storyboard,最简单的方法是在Storyboard中创建一个带有某个名称的segue。我们说show-image。然后你只需拨打performSegueWithIdentifier("show-image", sender: image)就可以了。其中image是您要传递的图像的一些参考(如果您愿意这样做)。如果您不想传递图像,只需在那里传递nil

然后覆盖prepareForSegue,检查segue.identifier是否等于show-image,然后将image引用(在这种情况下为sender)分配给某些segue.destinationViewController属性。

但是很难提供帮助或更具体,因为你没有提供有关错误的更多细节。

相关问题