Storyboardを見た感じだと、戻りたくて繋げているsegue
がありますが、
これだと戻る動作ではなく、新しく接続しているView
を表示するため、TabBar
が消えてしまいます。
戻るためには2種類あり、unwindSegue
を利用し戻る方法とコードで戻る方法があります。
どちらもコードを書きますが、大した内容ではないので、難しく考えないでください。
まず共通として、戻るためにつないでいるsegue
を削除してください。
1つ目のunwindSegue
では、
@IBAction func unwindToTop(segue: UIStoryboardSegue) {}
というコードを戻るためのボタンがあるViewに記載し、
storyboardで戻るボタンをCtrl+クリック
でViewの上にある3つの四角のうちのExit
に持って行きます。
すると先ほどコードに書いたunwindToTopが選択できるので、そちらを選択します。
2つ目のコードで戻るには、storyboardでAssistant Editor
を開き、
戻るためのボタンをCtrl+クリック
でコードに引っ張ります。
すると小さなウィンドウが出て、Connection
にAction
を選び、
下にあるName
に好きな名前をつけType
をUIButton
を選択してConnect
を押します。
class ViewController2: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func buttonPressed(sender: UIButton) {
}
}
するとこのような形になり、この下記の部分を
@IBAction func buttonPressed(sender: UIButton) {}
@IBAction func buttonPressed(sender: UIButton) {
self.dismissViewControllerAnimated(true, completion: nil)
}
に変えてあげて実行すれば戻ってもTabBarが表示されるはずです。
説明が下手で申し訳ないです。