确定JSQMessagesViewController上显示的消息数量

时间:2015-09-03 16:01:03

标签: ios jsqmessagesviewcontroller

我希望能够非常简单地了解JSQMessagesViewController当前显示的消息数量。找不到任何直接询问控制器的人。有吗?

2 个答案:

答案 0 :(得分:1)

获取可用消息总数:

 // If you don't have multiple sections, simply go get the number of message in the first section
 NSInteger numberOfAvailableMessages = [self.collectionView numberOfItemsInSection:0];

请注意在数据已经加载到屏幕后调用。

答案 1 :(得分:-1)

试试这个:

在query.limit中,您可以设置显示的消息数。即使我试图弄清楚这一点,但看到JesseHu在他的聊天示例中的实现。

func loadMessages() {
    if self.isLoading == false {
        self.isLoading = true
        var lastMessage = messages.last

        var query = PFQuery(className: <your class name>)
        query.whereKey(PF_CHAT_GROUPID, equalTo: groupId)// query params
        if lastMessage != nil {
            query.whereKey(PF_CHAT_CREATEDAT, greaterThan: lastMessage?.date)
        }
        query.includeKey(PF_CHAT_USER)
        query.orderByDescending(PF_CHAT_CREATEDAT)
        query.limit = 25
        query.findObjectsInBackgroundWithBlock({ (objects: [AnyObject]!, error: NSError!) -> Void in
            if error == nil {
                self.automaticallyScrollsToMostRecentMessage = false
                for object in (objects as! [PFObject]!).reverse() {
                    self.addMessage(object)
                }
                if objects.count > 0 {
                    self.finishReceivingMessage()
                    self.scrollToBottomAnimated(false)
                }
                self.automaticallyScrollsToMostRecentMessage = true
            } else {
                println("Network error")
            }
            self.isLoading = false;
        })
    }
}