https://developer.apple.com/documentation/uikit/uitabbardelegate/1623463-tabbar Official Apple reference.
If you want to do something when you tap the tabBar, use dedSelect
.
ViewController.swift
//Action when tapping tabbar
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
switch item.title {
case "news":
print("Tap a news item")
case "weather":
print("Tap the weather item")
case "Search":
print("Tap the search item")
default: break
}
}
In this sample code, the process is divided for each title of tabBar item in the switch statement. ʻItem.title` means that.
The tabBar is managed by the numbers tag [0.1.2 ...]
from the left, but when a third party sees the code, it's more like an item. Since I think that it is easier to understand if it is branched by title, it is ʻitem.title`.
Recommended Posts