使用 UIAlertAction 通过 Swift 递增标签栏上的徽章


 @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 badgeNumber = 0
        self.navigationController!.tabBarItem.badgeValue == "(badgeNumber++)"
    }
    let cancelAction = UIAlertAction(title: "Cancel", style: .Default, handler: nil)
    alertController.addAction(yesAction)
    alertController.addAction(cancelAction)
    presentViewController(alertController, animated: true, completion: nil)
}

我需要在警报上选择"是"以在每次按下标签栏项目时增加徽章,有人遇到过这个问题吗?

let yesAction = UIAlertAction(title: "Yes", style: .Default) { action in
      // Your code to update the tab bar here
}

另类:

UIAlertAction(title: "Yes", 
              style: UIAlertActionStyle.Default, 
            handler: { // Code goes here 
})

最新更新