2016-08-17 77 views
0

我得到了一個UITableViewController,該圖像從我的UIViewControllersegue呈現(作爲彈出窗口)。在UITableViewCell中,我有一個圖像,我從AppDelegate展示爲popover(因爲呈現圖像的函數可以在我的應用程序中隨處調用)。如何使用swift將多個控制器作爲彈出窗口顯示

我的問題:當時我不能出現超過1個控制器,我不得不關閉當前控制器來顯示我的圖像。

這裏是一些代碼:

// Function that is displaying my image(s) in my AppDelegate 
func showFullScreenImage(imageURL : String, imageArray : [String]) { 
    if AppDelegate.DeviceType.IS_IPAD { 
     let controller = UIStoryboard(name: "Storyboard_iPad", bundle: nil).instantiateViewControllerWithIdentifier("fullScreenImageViewController") as! FullScreenImageViewController 
     controller.popoverPresentationController?.sourceView = self.window!.rootViewController!.view 
     controller.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection() 
     controller.popoverPresentationController?.sourceRect = CGRectMake(self.window!.rootViewController!.view!.frame.width/2, self.window!.rootViewController!.view!.frame.height/2, 1, 1) 
     controller.mImageArray = imageArray 
     self.window!.rootViewController!.presentViewController(controller, animated: true, completion: nil) 
     controller.loadImage(imageURL) 
    } 
} 

這是我在做,以顯示我的圖片是什麼:

func displayImageFromComment(imageUrl: String, listImage: [String]) { 
    self.dismissViewControllerAnimated(true) { 
     (UIApplication.sharedApplication().delegate as! AppDelegate).showFullScreenImage(imageUrl, imageArray: listImage) 
    } 
} 

如果我不辭退,我得到這個錯誤:

Warning: Attempt to present MyApp.FullScreenImageViewController: 0x196530c0 on MyApp.RootViewController: 0x17e0f560 which is already presenting MyApp.BoardViewCommentsController: 0x181de000

之後,當我解僱正在顯示圖像的控制器時,我回到主要的UIViewController,NO T到我的UITableViewController

+0

導航控制器當時只能顯示1個控制器。你可以不用展示使用推動另一個視圖控制器,或者創建自定義動畫在你的根控制器上添加子視圖控制器(addChildViewCOntroller) – mbutan

+0

謝謝,我終於在全屏中使用了模態輪迴。但是,謝謝你給我這個解決方案。我認爲它將在未來幫助我。 –

回答

0

終於使用modal segue從我的UITableViewController到我的控制器顯示我的圖像。

它工作正常。