【发布时间】:2015-04-24 02:13:56
【问题描述】:
@IBAction func addToCart(sender: AnyObject) {
let itemObjectTitle = itemObject.valueForKey("itemDescription") as! String
let alertController = UIAlertController(title: "Add \(itemObjectTitle) to cart?", message: "", preferredStyle: .Alert)
let yesAction = UIAlertAction(title: "Yes", style: UIAlertActionStyle.Default) { (action) in
var tabArray = self.tabBarController?.tabBar.items as NSArray!
var tabItem = tabArray.objectAtIndex(1) as! UITabBarItem
let badgeValue = "1"
if let x = badgeValue.toInt() {
tabItem.badgeValue = "\(x)"
}
}
我不知道为什么我不能只做 += "(x)"
错误: 二元运算符“+=”不能应用于“字符串?”类型的操作数和'字符串'
我希望它在每次用户选择“是”时增加 1。现在显然它只是停留在 1。
【问题讨论】:
标签: ios swift swift2 swift3 uitabbaritem