0

When I receive a message I write the username and count of unread messages to CoreData. And with the help of this function:

func unreadMessagesCountBadge(cell: onlineUserCell, forCount count: Int)

I add to the cell my badge.

But the problem is, I do not know how to add this badge to exact user. When I get messages, I get this in logs:

data: {
    count = 15;
    username = "my_user@domain.com";
}

So, how can I with it add my badge to exact cell? On my cell I have just user's name and surname, not username.

When I try:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> onlineUserCell {
    let cell:onlineUserCell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! onlineUserCell

    unreadMessagesCountBadge(cell, forCount: badgeValue)
}

but it adds my badges to all users, not to exact user. Anyideas how can I fix it?

Orkhan Alizade
  • 7,379
  • 14
  • 40
  • 79

2 Answers2

0

Each element in the array that will be populated in the tableview should contain one identifier of the user..so in "cellForRow" you check which user is this and the you can take your badge from database according to the id.

Mejdi Lassidi
  • 999
  • 10
  • 22
0

When you call that method, you are not checking at all if the cell currently being populated is the same one which should have badge. So it gets called on every cell. In cellForRowAtIndexPath, check if cell.userName is equal to data's email (Wherever you are saving it in your model). If it is, call func unreadMessagesCountBadge(cell: onlineUserCell, forCount count: Int). You don't need the first parameter in this method anyways if you are checking email in cellForRowAtIndexPath.

NSNoob
  • 5,548
  • 6
  • 41
  • 54