私の問題は、ストーリーボードなしでUITabBarControllerを作成していて、ViewControllerなしでUITabBarアイテムを作成する方法が残っていることです。私がしたいのは、私のUITabBarItemの2番目のアイテムは、View Controllerを表示しないアクションです。あなたが本当にこれをしたい場合はView Controllerを使用せずにSwiftにuitabbarアイテムを作成する方法
0
A
答えて
0
は、その後、あなたは空のビューコントローラを追加するが、あなたのタブバーのデリゲートに
func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool {
}
0
は、私はこのような何かを実装して実装することができ(それは...かなり非標準のUIです)私はストーリーボードを使用していますが、アプリケーション(閉じるボタン)。閉じるボタンはViewControllerをであるが、私はそれが通常のボタンのように動作するために取得するには、次のコードを使用:
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
// this provides UI feedback that the button has been pressed, even though it leads to the dismissal
if viewController == self.viewControllers![4] {
viewController.tabBarItem.image? = UIImage(named: "TabBarClose")!.imageWithColor(UIColor.red).withRenderingMode(UIImageRenderingMode.alwaysOriginal)
return false
} else {
return true
}
}
override func viewDidDisappear(_ animated: Bool) {
//sets the close button back to original image
self.viewControllers![4].tabBarItem.image = UIImage(named: "TabBarClose")!
}
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
// this is so it never actually goes to the close buttons viewController
currentTab = self.selectedIndex != 4 ? self.selectedIndex:currentTab
saveTabIndexToPreferences(currentTab!)
}
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
// assign functionality to the close button
if item.tag == 100 {// this is old code, there is probably a better way to reference the tab
dismissTabBar()
} else {
}
}
(尋ねられた質問に対して)EDIT
func selectTabIndexFromPreferences() {
let defaults:UserDefaults = UserDefaults.standard
selectedIndex = defaults.integer(forKey: "songSelectionTabIndex_preference")
}
func saveTabIndexToPreferences(_ index:Int?) {
if index != nil {
let defaults:UserDefaults = UserDefaults.standard
defaults.set(index!, forKey: "songSelectionTabIndex_preference")
}
}
0
これを行うためのAPIが準拠しています。これらの線に沿ってhttps://developer.apple.com/documentation/uikit/uitabbarcontrollerdelegate/1621166-tabbarcontroller
何か:
UITabBarControllerDelegate
はあなたが実装することができshouldSelect
方法がある
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if (viewController == self.centerViewController) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Test" message:@"This is a test" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {}];
[alert addAction:defaultAction];
[tabBarController presentViewController:alert animated:YES completion:nil];
return NO;
}
return YES;
}
関連する問題
- 1. UITabBarを迅速に使用してView Controllerをナビゲートする方法は?
- 2. UITabBarControllerでプロジェクトを作成せずにUITabBarを使用する
- 3. Swift Segueを使用してView Controllerにデータを渡す方法は?
- 4. SwiftでView Controllerとそのコントロールをプログラムで作成する方法は?
- 5. iOS:View Controllerを使用せずにXIBを使用してプログラムでプログラムを作成する方法
- 6. Xcode、Swift、Table View Controller
- 7. .swiftを変更してView ControllerではなくTable View Controllerに接続する
- 8. Swift 3 View Controllerを表示
- 9. "Add" View Controllerを作成する最良の方法
- 10. iPhoneでカスタムPicker View Controllerを作成する方法は?
- 11. IOSでsegueを使用せずにView Controller間でデータを送信する方法9
- 12. Swift:ユーザーがTableviewセルをタップすると、あるView Controllerから別のView Controllerへデータをシフトする方法
- 13. 別のView ControllerでView Controllerを起動する方法は?
- 14. ListActivityを使用せずにListViewを作成する方法
- 15. add-functionを使用せずにArrayListを作成する方法
- 16. Membership.CreateUser()を使用せずにユーザーを作成する方法は?
- 17. 1つのView Controllerから別のView ControllerにUI ImageViewを渡す方法は? swift 3
- 18. Swift「show segue」は使用できませんCtrlボタンをView Controllerにドラッグ
- 19. 他のView Controller用にカスタムセルを再利用する方法は?
- 20. 別のView Controllerに戻って別のView Controllerに転送する方法
- 21. Swift 3でXIBを使用せずにNSViewControllerをプログラムで作成する
- 22. Swift View Controller with UITableViewセクション
- 23. UItabBarがView Controllerを変更しています
- 24. 複数のView ControllerでGameCenterManagerを使用する方法
- 25. ViewModelを使用せずにViewにLINQクエリを送信する方法
- 26. @Modelを使用せずに値をModelHelperにするTagHelperの作成方法は?
- 27. テーブルビューのセルから値を渡す方法Swiftを使用してボタンのアクションを他のView Controllerに渡す
- 28. Swiftのナビゲーションコントローラを使用せずにタブバーメニューを子ビューに伝播する方法
- 29. Tab Bar Itemに複数のView Controllerを持たせる方法
- 30. View Controllerにビューのクラスを知らせる方法は?
タブバーのインタフェースを使用して、しかし、1つのタブを有する*ない*新しいビューに移動し、ユーザーにとって非常に混乱する可能性があります。しかし、それをやりたいのであれば、 'UITabBarControllerDelegate'や' UITabBarDelegate'を参照してください。 – DonMag