1斯议、聲明一個deleagte
@objc protocol MVPTabBarDelegate : NSObjectProtocol { ? ? // MARK:--選中的 ?? ? func customTabBar(_ tabBar: MVPTabBar,? selectedIndex index: Int) }
2、點擊UIButton 執(zhí)行delegate
item.addTarget(self, action:#selector(tabBarItemAction(_:)), for: UIControlEvents.touchUpInside)
3、delegate.responds 安全檢測
@objc func tabBarItemAction(_ aItem:MVPTabBarItem) { ? ? ? ? print(aItem.tag) ?? ? ? ? ? ? ? ? self.selectedItem?.isSelected = false ? ? ? ? aItem.isSelected = true ? ? ? ? self.selectedItem = aItem; ?? ? ? ? ?? ? ? ? ? ? ? ? let result = delegate?.responds(to: #selector(delegate?.customTabBar(_:selectedIndex:))) ? ? ? ? if result==true { ? ? ? ? ? ? self.delegate?.customTabBar(self, selectedIndex: aItem.tag) ? ? ? ? } ?? ? ? ? ?? ? ? ? ?? ? ? ? ? ? }