确定在 JSQMessagesViewController 上显示多少消息

Determine how many messages are shown on JSQMessagesViewController

我希望有一种非常简单的方法来了解当前使用 JSQMessagesViewController 显示了多少条消息。找不到任何直接询问控制器的信息。有吗?

试试这个:

在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;
        })
    }
}

获取可用消息总数:

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

注意在数据加载到屏幕后调用