我在IOS 8中解决了我的问题,但我的代码在IOS 9中运行。我创建了一个透明按钮,并在Tabbar方法中添加子视图。问题是第二次tabar加载时按钮事件不起作用,这在IOS 8中是个问题,但它在ISO 9中运行良好。这是我的代码
委派
var button_ofTabbar = UIButton();
//var button_ofTabbar:UIButton!;
//UIButton();= UIButton(type: UIButtonType.System)
在标签栏中
class tabbar: UITabBarController,UITabBarControllerDelegate {
//let button_ofTabbar = UIButton();
var delegate1: AppDelegate!
let aDataBase : databaseinit = databaseinit()
override func viewDidLoad() {
super.viewDidLoad()
UITabBar.appearance().tintColor = UIColor(red: 242/255.0, green: 134/255.0, blue: 55/255.0, alpha: 1.0)
self.delegate=self;
delegate1 = UIApplication.sharedApplication().delegate as! AppDelegate
UITabBar.appearance().barTintColor = UIColor.whiteColor()
if(delegate1.tag_jive_channel_tab == 0)
{
// delegate1.button_ofTabbar.removeFromSuperview();
// delegate1.button_ofTabbar.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
delegate1.button_ofTabbar.hidden = false;
let widthofbtn:CGFloat = self.tabBar.frame.size.width/5;
delegate1.button_ofTabbar.frame = CGRectMake(0, self.tabBar.frame.origin.y, widthofbtn, self.tabBar.frame.size.height)
delegate1.button_ofTabbar.backgroundColor = UIColor.redColor()//clearColor()
//delegate1.button_ofTabbar = UIButton(type: UIButtonType.System)
delegate1.button_ofTabbar.tintColor = UIColor.redColor()//clearColor()
delegate1.button_ofTabbar.addTarget(self, action: "gotoShowChannel11", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(delegate1.button_ofTabbar);
}
}
override func viewDidAppear(animated: Bool) {
}
func gotoShowChannel11() {
delegate1.button_ofTabbar.hidden = true;
//orangeColor tabbar
//self.tabBarController?.tabBar.tintColor = UIColor.redColor();
delegate1.tag_jive_channel_tab = 1;
NSNotificationCenter.defaultCenter().postNotificationName("update_tabbar", object: nil,
userInfo: nil);
//UIColor(red: 146/255.0, green: 146/255.0, blue: 146/255.0, alpha: 1.0)
}
当我使用此行delegate1.button_ofTabbar = UIButton(type: UIButtonType.System)
时,我的按钮不会显示自定义/系统
我也试试这个func gotoShowChannel11(sender: UIButton!)
请帮我 。我陷入了IOS 8问题。和错误是
错误 - [__NSCFData gotoShowChannel11]
请任何人帮助我。
现在我找到了另一个解决方案。谢谢你。