I’m building an open source version of the native iPhone Messages app called AcaniChat. Each message is represented by a UITableViewCell with the timestamp at the top of the cell and the message below it.
Now, I’m implementing conditional timestamps, i.e., only show the timestamp for a message if that message is the first cell or if it’s been 15 minutes since the last timestamp shown.
When I go into edit mode for a conversation in the iPhone Messages app, it looks like each timestamp is its own cell. I’d like to do the same because eventually, I’d like to add edit mode support too.
-
So then, based on the
indexPath, how will I know whether to return a timestamp or a message cell? -
I’m using an
NSFetchedResultsControllerfor the messages. So, how do I keep track of the number of timestamps I’ve shown before a certain message so that I can use this as an offset when callingMessage *msg = [fetchedResultsController_ objectAtIndexPath:indexPath];?
In
viewDidLoad, after making thefetchRequestforMessageobjects, iterate through the results and create anNSMutableArray *cellMap, which you should also make an ivar. Set each element ofcellMaptocurrentTimestampormessage, depending on thepreviousTimestamp.Check out the ChatViewController of AcaniChat for the solution.