나는 탭이 4 개있는 UITabBar
입니다.페이지가 0 일 때 tabBar 항목을 눌렀을 때 감지
은 내가 tabBarItem
두 번 눌렀을 때 특정 기능이 탭의 각 ViewController
호출 할 것이다 (같은 사용자가 ProfileVC
에 지금과 Profile
항목 프레스, 내가보기를 새로 고칠)에합니다.
사용자가 현재보기에있는 탭을 눌렀을 때 어떻게 감지 할 수 있습니까?
감사합니다.
나는 탭이 4 개있는 UITabBar
입니다.페이지가 0 일 때 tabBar 항목을 눌렀을 때 감지
은 내가 tabBarItem
두 번 눌렀을 때 특정 기능이 탭의 각 ViewController
호출 할 것이다 (같은 사용자가 ProfileVC
에 지금과 Profile
항목 프레스, 내가보기를 새로 고칠)에합니다.
사용자가 현재보기에있는 탭을 눌렀을 때 어떻게 감지 할 수 있습니까?
감사합니다.
viewWillAppear()
방법 중 하나의 옵션이 새로 고침을 수행합니다. 그리고 두 번째 것은 상당히 길다. 각 탭보기 컨트롤러에서
protocol ParentDelegate {
func refresh()
}
class LandingViewController: UIViewController, UITabBarDelegate {
var delegate: ParentDelegate?
var selectedItem: UITabBarItem!
override func viewDidLoad() {
super.viewDidLoad()
self.tabBar.delegate = self
self.selectedItem = self.tabBar.selectedItem
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "SegueNameForDestinationViewController1" {
if let vc = segue.destinationViewController as? YourDestinationViewController1 {
self.delegate = vc.self
}
} else if segue.identifier == "SegueNameForDestinationViewController2" {
if let vc = segue.destinationViewController as? YourDestinationViewController2 {
self.delegate = vc.self
}
}
}
func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
if self.selectedItem == item {
self.delegate?.refresh()
}
self.selectedItem = item
}
}
부모 뷰 컨트롤러에서
,
class TabViewController: UIViewController, ParentDelegate {
func refresh() {
//write your code here
}
}
답변을 주셔서 감사합니다. 동일한 탭 항목을 다시 탭할 때'viewWillAppear()'이 호출되지 않습니다. 두 번째 옵션 인 스토리 보드는 사용하지 않습니다. 어떻게 할 수 있습니까? 감사! –
두 번째 대답은 스토리 보드가 필요하지 않습니다. 네가 이해하지 못하는 부분이 있니? – LIH
단편은 스토리 보드 용입니다. 그렇지 않습니까? –
는 u는 한 tabBar 위임 방법을 시도 했습니까? –
이 답변을보십시오. [Link] (http://stackoverflow.com/a/5455756/1896921) – AtWork