我有tableview ... 1表显示一个新的模态窗口,当我按下按钮时我想关闭模态窗口并推送到VC。我的代码只隐藏了模态视图,但没有进行推送。
@IBAction func registrationBtn(sender: AnyObject) {
let openNewVC = self.storyboard?.instantiateViewControllerWithIdentifier("registrationVcID") as! RegistrationVC
self.dismissViewControllerAnimated(false, completion: { () -> Void in
self.navigationController?.pushViewController(openNewVC, animated: true)
})
}
答案 0 :(得分:4)
您应该创建一个协议
protocol View1Delegate: class {
func dismissViewController(controller: UIViewController)
}
当您点击Register上的按钮时,会将委托调用回TableView。 TableViewController应该实现:
func dismissViewController(controller: UIViewController) {
controller.dismissViewControllerAnimated(true) { () -> Void in
//Perform segue or push some view with your code
}
}
你可以在这里做任何事情。推送你想要的屏幕。细节工具,你可以看到我的演示:Demo Push View in Swift
答案 1 :(得分:1)
Swift 3和4
的更新语法解雇视图控制器
self.dismiss(animated: true, completion: nil)
或者如果您想在完成块中执行某些操作(在视图被解除后),您可以使用...
self.dismiss(animated: true, completion: {
// Your code here
})
答案 2 :(得分:0)
self.navigationController在该完成块中没有做任何事情,因为它已被解雇。
而是创建一个在关闭当前视图时在父视图控制器上调用的委托。
angular.module('myApp')
.controller('MainController', function($scope, myFactory) {
[...]
myFactory.getActivities($scope.activityId, $scope.otherParameter, $scope.numPage,
$scope.numRegisters).then(
function(status) {
// you get the status from backend
// do whatever you want here
},
function(error) {
// fail to POST to backend
// implement your logic how to handle failure
}
);
});
然后在结束VC中,您可以存储委托并在完成块中调用它。
protocol PushViewControllerDelegate: class {
func pushViewController(vc: UIViewController)
}
您的展示视图控制器
中的实施weak var delegate: PushViewControllerDelegate?
self.dismissViewControllerAnimated(false, completion: { () -> Void in
let openNewVC = self.storyboard?.instantiateViewControllerWithIdentifier("registrationVcID") as! RegistrationVC
self.delegate?.pushViewController(openNewVC)
}