OptionViewController.swift:这是幻灯片菜单
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var option : OptionVO
option = viewOptions[indexPath.row]
var nav = UIStoryboard.navigationController(option.identifier)!
var detailController = nav.topViewController as DetailsViewController
detailController.currentView = option.name
self.revealViewController().revealToggleAnimated(true)
}
private extension UIStoryboard {
class func mainStoryboard() -> UIStoryboard { return UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()) }
class func navigationController(identifier : NSString) -> UINavigationController? {
return mainStoryboard().instantiateViewControllerWithIdentifier(identifier) as? UINavigationController
}
我有一个FrontViewController作为DetailsViewController.swift。
当我在幻灯片面板中选择一个不同的视图选项时,我只是执行了explainToggleAnimated(),它调出了FrontViewController。
现在,我想在DetailsViewController中为currentView变量使用此新视图集来更改屏幕
我想知道DetailsViewController完全显示后会收到什么回调,以便可以使用新设置的currentView变量。
仅供参考:
这些回调都不会被接收到:当调用exploringToggleAnimated()时,viewWillAppear,viewDidAppear,viewDidLoad都不会被接收。
解:
注册了SWRevealViewControllerDelegate:didMoveToPosition和调度通知:这是最终的代码片段
OptionViewController.swift [RearViewController]
override func viewDidLoad()
{
self.revealViewController().delegate = self
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var option : OptionVO
option = viewOptions[indexPath.row]
currentView = option.name
self.revealViewController().revealToggleAnimated(true)//didMoveToPosition is called when reveal is finished
}
func revealController(revealController: SWRevealViewController!, didMoveToPosition position: FrontViewPosition)
{
var notification = NSNotificationCenter.defaultCenter()
if let myNextView: AnyObject = currentView {
let viewDict = ["view" : myNextView]
notification.postNotificationName("ShowFrontVC",
object: nil,
userInfo: viewDict)
}
}
DetailsViewController.swift [FrontViewController]
func frontVCShown(notification:NSNotification)
{
let userInfo:Dictionary<String,String!> = notification.userInfo as Dictionary<String,String!>
currentView = userInfo["view"]
//change the view for currentView
}
最佳答案
如果我正确理解了您的问题,建议您自己发送一个NSNotification
。我将假设您正在为RearViewController使用tableView。
在您的RearViewController中
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[[NSNotificationCenter defaultCenter] postNotificationName:@"ShowFrontVC" object:nil userInfo:nil];
}
在您的FrontViewController中
- (void)viewDidLoad {
[super viewDidLoad];
// Add observer
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(frontVCShown) name:@"ShowFrontVC" object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
// Remove Observer
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)frontVCShown {
// Update your view controller
}
关于ios - SWRevealViewController:self.revealViewController()。revealToggleAnimated(true)时frontViewController上的回调是什么,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30131992/