我正在使用JSQMessagesViewController我的应用程序中与服务器通信的聊天功能.但是,聊天气泡非常难以预测,其大小永远无法正确调整.文本总是被切断,因为聊天气泡没有增加其宽度和高度以适合我的消息.我有以下代码:
#import "ChatViewController.h"
#import "JSQMessage.h"
#import "JSQMessagesTimestampFormatter.h"
#import "JSQMessagesBubbleImage.h"
#import "JSQMessagesBubbleImageFactory.h"
#import "User.h"
#import "AuthenticationHelper.h"
#import "Chat.h"
@interface ChatViewController ()
@property(strong, nonatomic)NSMutableArray* messagesArray;
@property(strong, nonatomic)User* myUser;
@property(strong, nonatomic)NSTimer* updateTimer;
@end
@implementation ChatViewController
#pragma mark - View lifecycle
/**
* Override point for customization.
*
* Customize your view.
* Look at the properties on `JSQMessagesViewController` and `JSQMessagesCollectionView` to see what is possible.
*
* Customize your layout.
* Look at the properties on `JSQMessagesCollectionViewFlowLayout` to see what is …Run Code Online (Sandbox Code Playgroud) 它的可能更改逻辑为collectionView:attributedTextForCellTopLabelAtIndexPath:showate方法,显示日期时间戳不是由indexPath.item%4 == 0?SOMessaging一天一天怎么样?管他呢?
此编码用于显示时间戳.
- (CGFloat)collectionView:(JSQMessagesCollectionView *)collectionView
layout:(JSQMessagesCollectionViewFlowLayout *)collectionViewLayout heightForCellTopLabelAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.item % 3 == 0) {
return kJSQMessagesCollectionViewCellLabelHeightDefault;
}
return 0.0f;
}
Run Code Online (Sandbox Code Playgroud)
当前存在的逻辑显示相同的时间戳重复如下.

我刚刚下载了Xcode 8 Beta,因此我可以在我的应用程序中包含一些新的iOS 10框架.但是,在将我的代码从Swift 2转换为Swift 3的过程中,我遇到了几个错误.除了一个超级烦人之外我修好了.
我收到错误:
无法调用非函数类型'JSQMessagesCollectionView!'的值 在以下代码行:
let cell = super.collectionView(collectionView, cellForItemAtIndexPath: indexPath) as! JSQMessagesCollectionViewCell
Run Code Online (Sandbox Code Playgroud)
这是我的整个上下文功能:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{
let cell = super.collectionView(collectionView, cellForItemAtIndexPath: indexPath) as! JSQMessagesCollectionViewCell
let message = messages[indexPath.item]
if message.senderId == senderId {
cell.textView!.textColor = UIColor.whiteColor()
} else {
cell.textView!.textColor = UIColor.blackColor()
}
return cell
}
Run Code Online (Sandbox Code Playgroud)
有人有想法吗?
Ps如果这有帮助,这是我的整个代码块:
import UIKit
import Firebase
import JSQMessagesViewController
class ChatViewController: JSQMessagesViewController {
// MARK: Properties
var rootRef = FIRDatabase.database().reference()
var messageRef: FIRDatabaseReference!
var messages …Run Code Online (Sandbox Code Playgroud) 我想为JSQMessageViewController我正在构建的应用程序发送文档文件.怎么做?
我创建了一个应用程序,我使用它JSQMessageViewController,它在iOS 8中工作正常.我在这个项目中使用Swift,我做桥接,因为库是用Objective-C编写的.但是在iOS 9,Xcode 7和Swift 2发布之后,我将我的代码语法转换为Swift 2并且出现问题..应用程序没有崩溃但是有一个日志错误...见下文.
2015-09-23 14:45:08.867 COC REAL WAR[1201:546997] Logging only once for UICollectionViewFlowLayout cache mismatched frame
2015-09-23 14:45:08.868 COC REAL WAR[1201:546997] UICollectionViewFlowLayout has cached frame mismatch for index path <NSIndexPath: 0xc000000000a00016> {length = 2, path = 0 - 5} - cached value: {{4, 693.221}, {312, 97}}; expected value: {{4, 596}, {312, 97}}
2015-09-23 14:45:08.868 COC REAL WAR[1201:546997] This is likely occurring because the flow layout subclass JSQMessagesCollectionViewFlowLayout is modifying attributes returned by UICollectionViewFlowLayout without copying …Run Code Online (Sandbox Code Playgroud) 我使用以下代码发送带有位置的JSQMessage,我没有任何错误,但消息没有在视图中显示.
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
var latestLocation: CLLocation = locations[locations.count-1]
let loc: JSQLocationMediaItem = JSQLocationMediaItem(location: latestLocation)
loc.appliesMediaViewMaskAsOutgoing = true
let locmessage: JSQMessage = JSQMessage(senderId: self.senderId, senderDisplayName: self.senderDisplayName, date: NSDate(), media: loc)
messages.append(locmessage)
self.finishSendingMessageAnimated(true)
}
Run Code Online (Sandbox Code Playgroud)
和
override func collectionView(collectionView: JSQMessagesCollectionView!, messageBubbleImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageBubbleImageDataSource! {
let factory = JSQMessagesBubbleImageFactory()
if messages[indexPath.row].senderId == senderId {
return factory.outgoingMessagesBubbleImageWithColor(UIColor.lightGrayColor())
} else {
return factory.incomingMessagesBubbleImageWithColor(UIColor.greenColor())
}
}
Run Code Online (Sandbox Code Playgroud)
其他类型的消息(照片和视频)没问题.
谁能帮我.
谢谢.
我有一个使用 Firebase 在用户之间发送和接收消息的应用程序。在将我的代码更新到新的 Swift 3 以便我可以将 iOS 10 的酷炫新功能添加到我的应用程序的过程中,我遇到了几个错误。我能够在运行时修复除此之外的大多数问题:
Terminating app due to uncaught exception 'InvalidPathValidation', reason: '(child:) Must be a non-empty string and not contain '.' '#' '$' '[' or ']''
Run Code Online (Sandbox Code Playgroud)
我不知道是什么原因造成的。用户登录时,其用户 ID 会打印到控制台,但只要按下登录按钮,我的应用程序就会崩溃。在我更新到 Swift 3 之前,这个错误是不存在的,实际上是在我修复了应用程序另一部分的错误后才出现的。
无论如何,我的应用程序中只有两个主要类:LoginViewController和ChatViewController。
这是代码LoginViewController:
import UIKit
import Firebase
class LoginViewController: UIViewController {
// MARK: Properties
var ref: FIRDatabaseReference! // 1
var userID: String = ""
override func viewDidLoad() {
super.viewDidLoad()
ref = FIRDatabase.database().reference() // 2
}
@IBAction func …Run Code Online (Sandbox Code Playgroud) 我正在尝试JSQMessagesVC在我的Swift 3项目中使用。它是通过可可豆荚安装的,一切看起来都很好。问题是我无法实现collectionView方法,并且不断出错。谁能帮我?

导入UIKit
导入JSQMessagesViewController
类ChatViewController:JSQMessagesViewController {
var messages = [JSQMessage]()
覆盖func viewDidLoad(){
super.viewDidLoad()
collectionView!.delegate =自我
collectionView!.dataSource =自我
collectionView!.collectionViewLayout.incomingAvatarViewSize = CGSize.zero
collectionView!.collectionViewLayout.outgoingAvatarViewSize = CGSize.zero
}
覆盖func collectionView(_ collectionView:JSQMessagesCollectionView,messageDataForItemAt indexPath:IndexPath)-> JSQMessageData {
返回消息[indexPath.item]
}
覆盖func collectionView(_ collectionView:UICollectionView,numberOfItemsInSection部分:Int)-> Int {
返回messages.count
}
覆盖func collectionView(_ collectionView:JSQMessagesCollectionView !, messageBubbleImageDataForItemAt indexPath:IndexPath!)-> JSQMessageBubbleImageDataSource!{
let message = messages [indexPath.item] // 1
如果message.senderId == senderId {// 2
返回outingBubbleImageView
} else {// 3
返回incomingBubbleImageView
}
}
覆盖func collectionView(_ collectionView:JSQMessagesCollectionView !, avatarImageDataForItemAt indexPath:IndexPath!)-> JSQMessageAvatarImageDataSource!{
返回零
}
懒惰的varoutingBubbleImageView:JSQMessagesBubbleImage … 我正在使用JSQMessagesViewController和Firebase在我的应用程序中实现聊天功能.我的ChatViewController中的一切都运行良好.但是现在我已经将我的ChatViewController移动到父视图控制器内的容器视图中,现在当扩展键盘时"发送"按钮不起作用.
换句话说,为了发送聊天消息,我必须调用view.endEditing(true)它本身在UITabBarController中的父视图控制器,然后发送按钮将起作用.但只要键盘展开,发送按钮就不会响应.下面是我的ChatViewController代码...
import Foundation
import UIKit
import FirebaseDatabase
import JSQMessagesViewController
final class ChatViewController: JSQMessagesViewController {
var outgoingBubbleImageView: JSQMessagesBubbleImage!
var incomingBubbleImageView: JSQMessagesBubbleImage!
var fireRootRef: FIRDatabaseReference!
var chatMessages = [JSQMessage]()
var messagesRefHandle: UInt!
var chatChannelId: String!
override func viewDidLoad(){
super.viewDidLoad()
self.inputToolbar.contentView.textView.backgroundColor = UIColor.clear
inputToolbar.alpha = 0.7
...
}
override func viewWillAppear(_ animated: Bool){
super.viewWillAppear(animated)
}
override func viewDidAppear(_ animated: Bool){
super.viewDidAppear(animated)
}
func setupView(){
...
}
override func viewWillDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
removeChatObserver()
}
func removeChatObserver(){
...
}
private …Run Code Online (Sandbox Code Playgroud) 在我的聊天应用程序中,我使用JSQMessagesViewController来呈现对话.要开始对话,我要在View控制器和标题的标题中添加收件人,这应该随着收件人数量的增长而增长.
我怎样才能实现这一目标?