gpt4 book ai didi

swift - 如何设置标签栏徽章?

转载 作者:行者123 更新时间:2023-11-30 14:06:03 27 4
gpt4 key购买 nike

我只是想添加一个“!”当有新项目时,并在点击选项卡栏后将其删除。我不知道在哪里放置下面的代码。

基本上,当有通知或创建新对话或更新现有对话时,我想要一个!在标签栏徽章上弹出,一旦用户点击所述标签栏项目!消失。

func conversationViewController(viewController: ATLConversationViewController, didSendMessage message: LYRMessage) {
println("Message sent!")

}




func conversationViewController(viewController: ATLConversationViewController, didFailSendingMessage message: LYRMessage, error: NSError?) {
println("Message failed to sent with error: \(error)")
}

func conversationViewController(viewController: ATLConversationViewController, didSelectMessage message: LYRMessage) {
println("Message selected")


}

// MARK - ATLConversationViewControllerDataSource methods

func conversationViewController(conversationViewController: ATLConversationViewController, participantForIdentifier participantIdentifier: String) -> ATLParticipant? {
if (participantIdentifier == PFUser.currentUser()!.objectId!) {
return PFUser.currentUser()!
}
let user: PFUser? = UserManager.sharedManager.cachedUserForUserID(participantIdentifier)
if (user == nil) {
UserManager.sharedManager.queryAndCacheUsersWithIDs([participantIdentifier]) { (participants: NSArray?, error: NSError?) -> Void in
if (participants?.count > 0 && error == nil) {
//self.addressBarController.reloadView()
// TODO: Need a good way to refresh all the messages for the refreshed participants...

self.reloadCellsForMessagesSentByParticipantWithIdentifier(participantIdentifier)

} else {
println("Error querying for users: \(error)")
}
}
}
return user
}

func conversationViewController(conversationViewController: ATLConversationViewController, attributedStringForDisplayOfDate date: NSDate) -> NSAttributedString? {
let attributes: NSDictionary = [ NSFontAttributeName : UIFont.systemFontOfSize(14), NSForegroundColorAttributeName : UIColor.grayColor() ]
return NSAttributedString(string: self.dateFormatter.stringFromDate(date), attributes: attributes as? [String : AnyObject])
}

func conversationViewController(conversationViewController: ATLConversationViewController, attributedStringForDisplayOfRecipientStatus recipientStatus: [NSObject:AnyObject]) -> NSAttributedString? {
if (recipientStatus.count == 0) {
return nil
}
let mergedStatuses: NSMutableAttributedString = NSMutableAttributedString()

let recipientStatusDict = recipientStatus as NSDictionary
let allKeys = recipientStatusDict.allKeys as NSArray
allKeys.enumerateObjectsUsingBlock { participant, _, _ in
let participantAsString = participant as! String
if (participantAsString == self.layerClient.authenticatedUserID) {
return
}

let checkmark: String = "✔︎"
var textColor: UIColor = UIColor.lightGrayColor()
let status: LYRRecipientStatus! = LYRRecipientStatus(rawValue: recipientStatusDict[participantAsString]!.unsignedIntegerValue)
switch status! {
case .Sent:
textColor = UIColor.lightGrayColor()
case .Delivered:
textColor = UIColor.orangeColor()
case .Read:
textColor = UIColor.greenColor()
default:
textColor = UIColor.lightGrayColor()
}
let statusString: NSAttributedString = NSAttributedString(string: checkmark, attributes: [NSForegroundColorAttributeName: textColor])
mergedStatuses.appendAttributedString(statusString)
}
return mergedStatuses;
}

// MARK - ATLAddressBarViewController Delegate methods methods


// MARK - ATLParticipantTableViewController Delegate Methods

func participantTableViewController(participantTableViewController: ATLParticipantTableViewController, didSelectParticipant participant: ATLParticipant) {
println("participant: \(participant)")
self.addressBarController.selectParticipant(participant)
println("selectedParticipants: \(self.addressBarController.selectedParticipants)")
self.navigationController!.dismissViewControllerAnimated(true, completion: nil)
}

func participantTableViewController(participantTableViewController: ATLParticipantTableViewController, didSearchWithString searchText: String, completion: ((Set<NSObject>!) -> Void)?) {
UserManager.sharedManager.queryForUserWithName(searchText) { (participants, error) in
if (error == nil) {
if let callback = completion {
callback(NSSet(array: participants as! [AnyObject]) as Set<NSObject>)
}
} else {
println("Error search for participants: \(error)")
}
}
}

}�

已解决 https://stackoverflow.com/a/29837976/2303865

最佳答案

假设您已将消息数查询到名为 counts 的变量中,然后将此计数显示到第一个 tabBarItem 中。

var arrayOfTabBar = self.tabBarController?.tabBar.items as NSArray!
let tabItem = arrayOfTabBar.objectAtIndex(1) as! UITabBarItem
tabItem.badgeValue = counts

关于swift - 如何设置标签栏徽章?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32383232/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com