0

I have a function, which adds badge on cell:

unreadMessagesCountBadge(cell, forCount: messagesCount)

but I do not know, how to detect cell what I need for adding this badge on it?

For example, I have a users list and one of my contacts sent me a message. How to detect this cell, to add near this contact my badge 1?

UPDATE

I detect that new message received in another file and I need to call this function from there and update in my cellForRowAtIndexPath. I'm confused =/

  • create a badge property in user list. add your badge to it and refresh the table view. also handle the badge property in `cellForRowAtIndexPath:`. – x4h1d Nov 03 '15 at 13:09
  • and one more question, you just touched this topic. How to **update** my tableView? When I do `reloadData( )` it doesn't help me. So, I need to change my controller and return back to see my badge. Any ideas about this problem? @x4h1d –  Nov 03 '15 at 13:15
  • `reloadData( )` should work fine if you handle updated data in `cellForRowAtIndexPath` correctly. Changing `viewcontroller`, just to refresh table view, will be ridiculous. Check `cellForRowAtIndexPath` method if your reload doesn't work. put break point and debug. – x4h1d Nov 03 '15 at 13:26
  • @x4h1d I've updated my question. Please read –  Nov 03 '15 at 13:30
  • I thing you should have used `singleton` class to handle data, as you said in your update that data is manipulated in different view controller and/or class. Create a singleton model class. Singleton [help](http://stackoverflow.com/questions/15383452/objective-c-sample-singleton-implementation). Or you can invoke method in another class, which aren't connected to each other, via `NSNotificationCenter`. – x4h1d Nov 03 '15 at 13:35

1 Answers1

1

Why doesn't it help you when using reloadData() on your tableView? Are you calling it from the main thread? You can force calling from main thread:

dispatch_async(dispatch_get_main_queue(),{
  self.tableView.reloadData()
})
battlepope
  • 290
  • 3
  • 17