Skip to content

Commit 8399e7c

Browse files
committed
Fix controllers not popping when pressing a tab bar button
1 parent dae8274 commit 8399e7c

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

trySwift.xcodeproj/project.pbxproj

+12
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
49F7B2811E8475F900F09768 /* SplitViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49F7B2801E8475F900F09768 /* SplitViewController.swift */; };
2929
4D498DB1B98D4B496FDBB7AA /* Pods_try__Extension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD2E9D5733A6E1B6E10AFEEF /* Pods_try__Extension.framework */; };
3030
5CDB20792048952A00C3E0D3 /* TwitterFollowDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CDB20782048952A00C3E0D3 /* TwitterFollowDelegate.swift */; };
31+
5C7F82DB2048B01D009193B4 /* RootTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C7F82DA2048B01D009193B4 /* RootTabBarController.swift */; };
3132
7AD1E19C80B78BB08E3DF079 /* Pods_trySwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 620220ABCCCDF47FDAF48B67 /* Pods_trySwift.framework */; };
3233
EAFE1C26E49EFABF83487BDC /* Pods_try__Today.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24718BF11477753FCD47A7A8 /* Pods_try__Today.framework */; };
3334
FA0E2B4F1E63B90400B40814 /* SessionDetailInterfaceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA0E2B4E1E63B90400B40814 /* SessionDetailInterfaceController.swift */; };
@@ -195,6 +196,7 @@
195196
49F7B2801E8475F900F09768 /* SplitViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SplitViewController.swift; sourceTree = "<group>"; };
196197
58F81AD508535BD405F98215 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
197198
5CDB20782048952A00C3E0D3 /* TwitterFollowDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwitterFollowDelegate.swift; sourceTree = "<group>"; };
199+
5C7F82DA2048B01D009193B4 /* RootTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootTabBarController.swift; sourceTree = "<group>"; };
198200
5FA07FBC036240AEF8B7C739 /* Pods-trySwift.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-trySwift.release.xcconfig"; path = "Pods/Target Support Files/Pods-trySwift/Pods-trySwift.release.xcconfig"; sourceTree = "<group>"; };
199201
620220ABCCCDF47FDAF48B67 /* Pods_trySwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_trySwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
200202
6C1F9C27BCD8099DCA758F7A /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; };
@@ -391,6 +393,14 @@
391393
path = Twitter;
392394
sourceTree = "<group>";
393395
};
396+
5C7F82D92048B00B009193B4 /* RootTabBar */ = {
397+
isa = PBXGroup;
398+
children = (
399+
5C7F82DA2048B01D009193B4 /* RootTabBarController.swift */,
400+
);
401+
path = RootTabBar;
402+
sourceTree = "<group>";
403+
};
394404
F413680C9BA29129B4319377 /* Pods */ = {
395405
isa = PBXGroup;
396406
children = (
@@ -425,6 +435,7 @@
425435
FA39E8C51C6AB7310074B6BE /* ViewControllers */ = {
426436
isa = PBXGroup;
427437
children = (
438+
5C7F82D92048B00B009193B4 /* RootTabBar */,
428439
FA39E8FB1C6C26150074B6BE /* Schedule */,
429440
FA39E9061C6C43480074B6BE /* Speakers */,
430441
FABA73BF1D6D9ACE0081D887 /* OfficeHours */,
@@ -1138,6 +1149,7 @@
11381149
files = (
11391150
5CDB20792048952A00C3E0D3 /* TwitterFollowDelegate.swift in Sources */,
11401151
499BD62A1D05910200E74061 /* Twitter.swift in Sources */,
1152+
5C7F82DB2048B01D009193B4 /* RootTabBarController.swift in Sources */,
11411153
FA39E90F1C6C81870074B6BE /* SponsorsViewController.swift in Sources */,
11421154
FA36B7071E5DA3970022E6A9 /* DateFormatterExtension.swift in Sources */,
11431155
FAA54F141D9130F900EC9E80 /* UITableViewExtension.swift in Sources */,

trySwift/Base.lproj/Main.storyboard

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1010
</dependencies>
1111
<scenes>
12-
<!--Tab Bar Controller-->
12+
<!--Root Tab Bar Controller-->
1313
<scene sceneID="mld-K4-cXp">
1414
<objects>
15-
<tabBarController id="Xe8-8h-xaI" sceneMemberID="viewController">
15+
<tabBarController id="Xe8-8h-xaI" customClass="RootTabBarController" customModule="trySwift" customModuleProvider="target" sceneMemberID="viewController">
1616
<tabBar key="tabBar" contentMode="scaleToFill" id="Iea-je-7kA">
1717
<rect key="frame" x="0.0" y="0.0" width="320" height="49"/>
1818
<autoresizingMask key="autoresizingMask"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// RootTabBarController.swift
3+
// trySwift
4+
//
5+
// Created by Sash Zats on 3/2/18.
6+
// Copyright © 2018 NatashaTheRobot. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class RootTabBarController: UITabBarController, UITabBarControllerDelegate {
12+
override func viewDidLoad() {
13+
super.viewDidLoad()
14+
self.delegate = self
15+
}
16+
17+
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
18+
if let splitViewController = viewController as? UISplitViewController {
19+
if let navigationController = splitViewController.viewControllers.last as? UINavigationController,
20+
navigationController.viewControllers.count > 1 {
21+
navigationController.popViewController(animated: true)
22+
}
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)