Last active
August 23, 2018 17:42
-
-
Save RichGreenTea/883ac3823e5833c031324c68a9d1fb7f to your computer and use it in GitHub Desktop.
Eurekaで非同期処理で取得したデータでフォームを更新して画面に反映させる ref: https://qiita.com/RichGreenTea/items/dda86ab643f01ea5b0fa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.form.allRows.forEach({$0.updateCell(); $0.reload()}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Eureka | |
final class ExampleFormViewController: FormViewController { | |
private var user: User? | |
... | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
setView() | |
setForm() | |
fetchUser() | |
} | |
private func setView() { | |
... | |
} | |
private func setForm() { | |
self.form | |
+++ Section("User info") | |
<<< TextRow() { row in | |
row.title = "Name" | |
row.placeholder = "hoge fuga" | |
}.cellUpdate { [unowned self] cell, row in | |
// フェッチしたuserのnameを代入 | |
row.value = self.user?.name | |
} | |
... | |
} | |
private func fetchUser() { | |
let successHandler: (User) -> Void = { user in | |
self.user = user | |
// フォームを更新・画面に反映 | |
self.form.allRows.forEach({$0.updateCell(); $0.reload()}) | |
} | |
UserLogic.get(successHandler: successHandler, failureHandler: {_ in}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment