如何根据TabBar徽章值iOS Swift突出显示UITableVIewCell?

时间:2017-03-01 17:50:38

标签: ios swift uitableview

我想根据tabbar徽章值突出显示单元格文本。一旦用户收到通知,我就会在标签栏上显示徽章计数,但在刷新视图后,我希望根据当前的标签栏标记值突出显示该单元格。请帮帮我这个

I want to achieve according to attached image

 let jsonObject = try? NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments)
            print(jsonObject)
            let responseDict:NSDictionary = jsonObject as! NSDictionary
            let messagesDictionary:NSDictionary? = responseDict.objectForKey("Data") as? NSDictionary

            appDelegate.messagesBadgeCount = messagesDictionary?.objectForKey("UnReadMessages") as! NSInteger

            if appDelegate.messagesBadgeCount > 0 {
                self.tabBarController?.tabBar.items?[0].badgeValue = String(appDelegate.messagesBadgeCount)
                if #available(iOS 10.0, *) {
                    self.tabBarController?.tabBar.items![0].badgeColor = UIColor(red: 219/255.0, green: 90/255.0, blue: 41/255.0, alpha: 1)
                } else {
                    // Fallback on earlier versions
                }

            }

我从JSON响应中获取徽章计数,但我没有任何特定单元格天气的标识符读取或未读取。在这里,我想根据徽章值突出显示顶部单元格,一旦用户点击我调用didSelectRowAtIndexPath的单元格来清除tabbar徽章值。 在这里,我想清除徽章值和突出显示的单元格一旦didSelectRowAtIndexPath调用。

提前致谢

谢谢@Koen我现在正在进行以下更改,但突出显示的文本UITableViewCell将返回所有单元格。如何根据徽章值

限制突出显示的细胞计数

在cellForRowAtIndexPath中进行以下更改

  if appDelegate.messageCount > 0 {

        if childDictionary is Dictionary<String, AnyObject> {
            let cell = tableView.dequeueReusableCellWithIdentifier("UnReadMessageTableViewCell", forIndexPath: indexPath) as! UnReadMessageTableViewCell

            cell.userIdChildLabel2.text = dictionary? ["UserId"] as? String
            cell.dateChildLabel2.text = dictionary? ["Date"] as? String
            cell.subjectChildLabel2.text = dictionary? ["ActivityText"] as? String
            cell.predicateChildLabel2.text = dictionary? ["Predicate"] as? String
            cell.activityChildLabel2.text = childDictionary? ["ActivityText"] as? String


            let modifiedDate = dictionary? ["Date"] as? String
            let modifiedTime = dictionary? ["Time"] as? String
            if modifiedTime != nil && modifiedDate != nil {
                let dateTime:String = modifiedDate! + " " + modifiedTime!
                cell.dateChildLabel2.text = getTimeZoneDate(dateTime)
            }
            if let imageView = dictionary? ["ProfilePicUrl"] as? String{
                cell.profileImageChildLabel2.sd_setImageWithURL(NSURL(string:imageView ), placeholderImage : UIImage(named: "DefaultImage"))

            }
            return cell            
    }

0 个答案:

没有答案