@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
})

关于ios - 使用UIAlertAction通过Swift增加标签栏上的标志,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29835340/

10-12 01:24