iPhone Messages应用程序中的每个时间戳都是其自己的单元格吗? [英] Is each timestamp in the iPhone Messages app its own cell?

查看:56
本文介绍了iPhone Messages应用程序中的每个时间戳都是其自己的单元格吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个名为AcaniChat的本机iPhone Messages应用程序的开源版本.每个消息都由 UITableViewCell 表示,时间戳位于单元格的顶部,消息位于其下方.

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.

现在,我正在实现条件时间戳记,即,仅在该消息是第一个单元格或者距显示的最后一个时间戳记已超过15分钟时才显示该消息的时间戳记.

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.

当我进入iPhone消息应用程序中的对话的编辑模式时,看起来每个时间戳都是其自己的单元格.我想这样做,因为最终我也想添加编辑模式支持.

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. 然后,基于 indexPath ,我怎么知道是返回时间戳还是消息单元格?

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

我正在为消息使用 NSFetchedResultsController .因此,如何跟踪某条消息之前显示的时间戳数,以便在调用 Message * msg = [fetchedResultsController_ objectAtIndexPath:indexPath]; 时可以将其用作偏移量?

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];?

推荐答案

viewDidLoad 中,对 Message 对象进行 fetchRequest 后,进行迭代浏览结果并创建一个 NSMutableArray * cellMap ,您还应该将其设为ivar.将 cellMap 的每个元素设置为 currentTimestamp message ,具体取决于 previousTimestamp .

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.

查看<的 ChatViewController a href ="https://github.com/acani/AcaniChat" rel ="nofollow"> AcaniChat 作为解决方案.

Check out the ChatViewController of AcaniChat for the solution.

这篇关于iPhone Messages应用程序中的每个时间戳都是其自己的单元格吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆