Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get value back #134

Open
HUANGLIWEN opened this issue Sep 24, 2019 · 2 comments
Open

get value back #134

HUANGLIWEN opened this issue Sep 24, 2019 · 2 comments

Comments

@HUANGLIWEN
Copy link

VC A->VC B,Now i want get B page value in A Page how should i do?

@devxoul
Copy link
Owner

devxoul commented Sep 28, 2019

You can use context:

struct MyContext {
  let completionHandler: (MyData) -> Void
}

navigator.register("myapp://") { url, values, context in
  guard let context = context as? MyContext else { return nil }
  return ViewControllerB(completionHandler: context.completionHandler)
}

// in ViewControllerA.swift
let context = MyContext(completionHandler: { ... })
navigator.push(viewControllerB, context: context)

@FunnyerFeng
Copy link

You can use context:

struct MyContext {
  let completionHandler: (MyData) -> Void
}

navigator.register("myapp://") { url, values, context in
  guard let context = context as? MyContext else { return nil }
  return ViewControllerB(completionHandler: context.completionHandler)
}

// in ViewControllerA.swift
let context = MyContext(completionHandler: { ... })
navigator.push(viewControllerB, context: context)

push方法有返回viewcontroller,我返回了一个基类,基类内有个公共的闭包,在闭包内实现回调也是可行的吧? 因为我push 的时候把context 仅作为Dictionary 传参处理的,感觉比在url 上传参清晰

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants