我想在模態被解除後調用視圖控制器上的功能。我花了幾個小時試圖讓這個工作,我發現所有的反應都沒有奏效。我遵循其他人的指示並建立了一個協議,但這仍然不起作用。Swift中模態被解除後的運行功能
MainController:
class ViewController: UIViewController, UIPopoverPresentationControllerDelegate, loadStoreDelegate{
然後以觸發予使用
func displaySelectStorePopup(){
if let viewController = self.storyboard?.instantiateViewControllerWithIdentifier("SelectStoreView"){
let selectStoreController = viewController
selectStoreController.modalPresentationStyle = .Popover
if let sctrl = selectStoreController.popoverPresentationController{
sctrl.delegate = self
sctrl.sourceView = self.view
sctrl.sourceRect = CGRectMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds),0,0)
sctrl.permittedArrowDirections = UIPopoverArrowDirection()
delay(0.1){
sctrl.passthroughViews = nil
}
selectStoreController.modalInPopover = true
selectStoreController.preferredContentSize = CGSizeMake(400, 400)
self.presentViewController(selectStoreController, animated: true, completion: nil)
}
}
}
然後函數ID喜歡用
func loadStore() {
print(2)
//let vc : AnyObject! = self.storyboard!.instantiateViewControllerWithIdentifier("DashboardView")
//self.showViewController(vc as! UIViewController, sender: vc)
}
ModalViewController模態: 協議
protocol loadStoreDelegate{
func loadStore()
}
class SelectStoreViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{...
var delegate: loadStoreDelegate?
然後調用上的tableview點擊
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
self.delegate?.loadStore()
if(tableView == selectStoreTable){
currentStore = userStores[indexPath.row]
self.dismissViewControllerAnimated(false, completion: nil)
}
}
要調用'loadStore( )'_before_調用'self.dismissViewControllerAnimated(false,completion:nil)'。所以這不是「被解僱後」。 – matt
您是否在'didSelectRowAtIndexPath'中設置了一個斷點來查看發生了什麼? – Paulw11
是的,我從代表中得到了一個零值 –