###前提・実現したいこと
遷移した段階でTabPageViewController
を表示させたい。
###発生している問題・エラーメッセージ
Alamofire
の処理の中にTabPageViewController
のcreate()
以降の処理を記述すると
タブをスワイプするなどの動作をしないと設定したタブバーが表示されない。
★通信結果によってはじめに表示されるタブを変更したい。
★受け取ったjson["result"]
の結果がnil
の場合は0番めのタブを。
★受け取ったjson["result"]
の結果がnil
の場合は1番めのタブを。
現在の構造は
viewDidLoad
−−check()
−−−tabPageSetting()
###該当のソースコード
import UIKit import Alamofire import SwiftyJSON import TabPageViewController class ViewController: UIViewController { let server: String = "http://sample.jp" let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate override func viewDidLoad() { super.viewDidLoad() self.navigationItem.title = "テスト" self.navigationController!.interactivePopGestureRecognizer!.enabled = false check() } func tabPageSetting(setIndex: Int) { let tabPageViewController = TabPageViewController.create() let vc1 = self.storyboard?.instantiateViewControllerWithIdentifier("Tab1") as! Tab1ViewController let vc2 = self.storyboard?.instantiateViewControllerWithIdentifier("Tab2") as! Tab2ViewController let vc3 = self.storyboard?.instantiateViewControllerWithIdentifier("Tab3") as! Tab3ViewController tabPageViewController.tabItems = [(vc1, "タブ1"), (vc2, "タブ2"), (vc3, "タブ3")] tabPageViewController.displayControllerWithIndex(setIndex, direction: .Forward, animated: false) var option = TabPageOption() option.currentColor = UIColor.redColor() option.tabWidth = view.frame.width / CGFloat(tabPageViewController.tabItems.count) tabPageViewController.option = option tabPageViewController.view.frame.origin.y += (self.tabBarController?.tabBar.frame.height)! tabPageViewController.view.frame.size.height -= (self.tabBarController?.tabBar.frame.height)! self.addChildViewController(tabPageViewController) self.view.addSubview(tabPageViewController.view) tabPageViewController.didMoveToParentViewController(self) } func check() { Alamofire.request(.GET, "\(server)/api/test", headers: appDelegate.customHeader) .responseJSON { response in guard let object = response.result.value else { return } let json = JSON(object) if json["result"].int == nil { self.tabPageSetting(0) } else { self.tabPageSetting(1) } } } }
###試したこと
override func viewDidLoad() { super.viewDidLoad() self.navigationItem.title = "テスト" self.navigationController!.interactivePopGestureRecognizer!.enabled = false tabPageSetting(0) }
Alamofire
内で処理をしなければ、普通に表示されます。
###補足情報(言語/FW/ツール等のバージョンなど)
・Xcode7.3.1
・Swift2
・TabPageViewController (0.2.1)
###追記
fuzzballさん
override func viewDidLoad() { super.viewDidLoad() self.navigationItem.title = "テスト" self.navigationController!.interactivePopGestureRecognizer!.enabled = false tabPageSetting(0) check() }
これで再度実行しましたが結果は変わらずでした。
回答3件
あなたの回答
tips
プレビュー