如何在iOS Swift中将数据数组回调到另一个viewController [英] how to callback the array of data to another viewController in iOS Swift
本文介绍了如何在iOS Swift中将数据数组回调到另一个viewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在createCardVC中,我使用了carbonKit库来显示选项卡栏。最初,使用静态数据加载数据数组,但现在我尝试使用来自webView javascript postMessage的数据数组。
In createCardVC, I have used the carbonKit library to show tab bar. Initially, the array of data loaded using static data but now I am trying to use an array of data from webView javascript postMessage.
- 加载createCardVC时,第一个选项卡的carbonKit将加载webViewVC。
- 在webView,从postMessage它将列出数字菜单项以显示选项卡栏菜单。
- 此处的选项卡值是动态的,并且将从webView postMessage返回。
这是清晰的图片:
这是代码createCardVC:
Here is the code createCardVC:
override public func viewDidLoad() {
super.viewDidLoad()
carbonTabSwipeNavigation = CarbonTabSwipeNavigation(items: ["Basic Details"], delegate: self)
carbonTabSwipeNavigation.insert(intoRootViewController: self, andTargetView: infoView)
carbonTabSwipeNavigation.toolbar.barTintColor = UIColor.white
carbonTabSwipeNavigation.setSelectedColor(UIColor.black)
carbonTabSwipeNavigation.setIndicatorColor(UIColor(hexString: "#363794"))
}//viewdidload
func onUserAction(data: String)
{
print("Data received: \(data)")
}
func sampleDelegateMethod(arg: Bool,completion: (Bool) -> ()){
completion(arg)
let singleTon = SingletonClass()
print(singleTon.sharedInstance.dataText)
}
@IBAction func backBtn(_ sender: Any) {
_ = navigationController?.popViewController(animated: true)
navigationController?.setNavigationBarHidden(false, animated: true)
tabBarController?.tabBar.isHidden = false
}
public init() {
super.init(nibName: "CreateCardViewController", bundle: Bundle(for: CreateCardViewController.self))
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public func carbonTabSwipeNavigation(_ carbonTabSwipeNavigation: CarbonTabSwipeNavigation, viewControllerAt index: UInt) -> UIViewController {
return firstView()
}
func firstView() -> UIViewController {
let cont = WebViewController()
self.tabContView?.addChild(cont)
self.tabContView?.view.addSubview(cont.view)
cont.didMove(toParent: tabContView)
let authToken = UserDefaults.standard.string(forKey: "authToken")
cont.formKey = formKey
print("cont vl", formKey ?? "")
cont.processInstanceId = processInstanceId
cont.authTokenValue = authToken
cont.fullFormKey = fullFormKey
cont.taskIdValue = TaskIdValue
return cont
}
以下是webView的代码:
Here is the code for webView:
public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
if message.name == "jsHandler" {
// print(message.body)
} else if message.name == "tabForm" {
print("dynamic tabs value::::",message.body)
let tabs = message.body
let jsonString = JSONStringify(value: tabs as AnyObject)
if let jsonData = jsonString.data(using: .utf8) {
do {
let decoder = JSONDecoder()
let mainObject = try decoder.decode(DynamicTabsModel.self, from: jsonData)
print("tab model:::", mainObject)
createCardVC?.onUserAction(data: "The quick brown fox jumps over the lazy dog")
delegate?.onPizzaReady(type: "Pizza di Mama")
createCardVC?.sampleDelegateMethod(arg: true, completion: { (success) -> Void in
print("Second line of code executed")
if success { // this will be equal to whatever value is set in this method call
createCardVC?.onUserAction(data: "The quick brown fox jumps over the lazy dog")
delegate?.onPizzaReady(type: "Pizza di Mama")
let singleTon = SingletonClass()
singleTon.sharedInstance.dataText = "store data"
print("delegate method ::: true")
} else {
print("delegate method ::: false")
}
})
print("called delegate")
} catch {
print(error.localizedDescription)
}
}
}
}
我的问题是:
- 如何将标签值从webView返回到CreateCardVC?
- 如何在carbonKit中显示动态选项卡?
- 如何使用相同的webViewController和url从webViewController返回动态更改下一个选项卡的ViewController。
任何帮助都值得赞赏...
Any help much appreciated pls...
推荐答案
您可以尝试使用 GLViewPagerController ,它更具动态性,API与 UITableView相似。
You can try using "GLViewPagerController" it is more dynamic and API is similar to "UITableView"
这里是链接: GLViewPagerController
其他选项:
- Parchment
- PolioPager
这篇关于如何在iOS Swift中将数据数组回调到另一个viewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文