모달을 닫은 후에 뷰 컨트롤러에서 함수를 호출하려고합니다. 나는이 일을하기 위해 많은 시간을 보냈으며, 내가 찾은 모든 반응은 효과가 없었다. 나는 다른 사람들의 지시를 따르고 프로토콜을 설정했지만 여전히 작동하지 않습니다.모달을 Swift에서 닫은 후 함수를 실행하십시오.
MainController : 프로토콜
:class ViewController: UIViewController, UIPopoverPresentationControllerDelegate, loadStoreDelegate{
그럼 난 그런 기능 ID가
func loadStore() {
print(2)
//let vc : AnyObject! = self.storyboard!.instantiateViewControllerWithIdentifier("DashboardView")
//self.showViewController(vc as! UIViewController, sender: vc)
}
ModalViewController를 사용하려면
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)
}
}
}
를 사용하는 모달 트리거
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 (거짓, 완료 : 없음)'. 그래서 그것은 "해산 된 이후"가 아닙니다. – matt
'didSelectRowAtIndexPath'에 중단 점을 설정하여 어떤 일이 발생했는지 확인 했습니까? – Paulw11
예 위임자로부터 nil 값을 얻습니다. –