1、声明一个deleagte
@objc protocol MVPTabBarDelegate : NSObjectProtocol { // MARK:--选中的 func customTabBar(_ tabBar: MVPTabBar, selectedIndex index: Int) }
2、点击UIButton 执行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) } }
网友评论