Is each timestamp in the iPhone Messages app its own cell?

走远了吗. 提交于 2019-12-24 10:38:08

问题


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.

  1. So then, based on the indexPath, how will I know whether to return a timestamp or a message cell?

  2. I'm using an NSFetchedResultsController for 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 calling Message *msg = [fetchedResultsController_ objectAtIndexPath:indexPath];?


回答1:


In viewDidLoad, after making the fetchRequest for Message objects, iterate through the results and create an NSMutableArray *cellMap, which you should also make an ivar. Set each element of cellMap to currentTimestamp or message, depending on the previousTimestamp.

Check out the ChatViewController of AcaniChat for the solution.



来源:https://stackoverflow.com/questions/5561688/is-each-timestamp-in-the-iphone-messages-app-its-own-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!