我正在构建一个名为 AcaniChat 的原生 iPhone 消息应用程序的开源版本。每条消息都由 UITableViewCell
表示,时间戳位于单元格顶部,消息位于单元格下方。
现在,我正在实现条件时间戳,即,仅当该消息是第一个单元格或者自上次显示的时间戳以来已经过了 15 分钟时,才显示该消息的时间戳。
当我进入 iPhone 消息应用程序中的对话编辑模式时,看起来每个时间戳都是其自己的单元格。我想做同样的事情,因为最终我也想添加编辑模式支持。
-
那么,基于indexPath
,我如何知道是返回时间戳还是消息单元格?
-
我正在使用 NSFetchedResultsController
来发送消息。那么,如何跟踪在某个消息之前显示的时间戳数量,以便在调用 Message *msg = [fetchedResultsController_ objectAtIndexPath:indexPath];
时将其用作偏移量?
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 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)
在 viewDidLoad 中,为
Message
对象创建fetchRequest
后,迭代结果并创建一个NSMutableArray *cellMap
,你也应该做一个伊瓦尔。将cellMap
的每个元素设置为currentTimestamp
或message
,具体取决于previousTimestamp
。查看 ChatViewController “https://github.com/acani/AcaniChat” rel="nofollow">AcaniChat 获取解决方案。
In
viewDidLoad
, after making thefetchRequest
forMessage
objects, iterate through the results and create anNSMutableArray *cellMap
, which you should also make an ivar. Set each element ofcellMap
tocurrentTimestamp
ormessage
, depending on thepreviousTimestamp
.Check out the ChatViewController of AcaniChat for the solution.