A、B二つの画面があり、それぞれタブバーのアイコンをタップすることにより、遷移します。(タブバーのアイコンは二つ)
B画面に存在するボタンをタップし、B'画面に遷移し、B'画面に存在するボタンをタップしてA画面に戻るという流れがあります。
B'画面はサブ画面なので、タブバーは表示されなくて良いのですが、A画面に戻った時にタブバーが表示されるようにしたいです。
プログラムソースは以下です。(Storyboardを使わずにコードで実装したい)
// UITabBarControllerを継承したクラスを作成
class MainTabBarController: UITabBarController {
override func viewDidLoad() { super.viewDidLoad() let firstViewController = FirstViewController() let secondViewController = SecondViewController() firstViewController = UITabBarItem(tabBarSystemItem: UITabBarSystemItem.Bookmarks, tag: 1) secondViewController = UITabBarItem(tabBarSystemItem: UITabBarSystemItem.Contacts, tag: 2) let firstNavigationController = UINavigationController(rootViewController: firstViewController) let secondNavigationController = UINavigationController(rootViewController: secondViewController) self.setViewControllers([firstNavigationController, secondNavigationController], animated: true) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() }
}
// AppDelegate.swiftのメソッドを変更
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
self.window = UIWindow(frame: UIScreen.mainScreen().bounds) self.window?.rootViewController = mainTabBarController self.window?.makeKeyAndVisible() return true
}
// B画面からB'画面への遷移
let nextViewController = bDashViewController()
let navigationController = UINavigationController(rootViewController: nextViewController)
self.presentViewController(navigationController, animated: false, completion: nil)
// B'画面からA'画面への遷移
// 遷移後タブバーを表示したい
let nextViewController = firstViewController()
let navigationController = UINavigationController(rootViewController: nextViewController)
self.presentViewController(navigationController, animated: false, completion: nil)
よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/12/02 08:01