JSQMessagesController 文本视图卡住了
JSQMessagesController textview stuck
发送 2-3 条消息后,我的 TextView 卡住了。我的 iOS 版本是 10.2.1,测试设备是 iPhone 6Plus,JSQMessagesViewController 版本是 7.3.4,代码在 Obj-C 中。我已经实现了以下方法:
-(void)didPressSendButton:(UIButton *)button withMessageText:(NSString *)text senderId:(NSString *)senderId senderDisplayName:(NSString *)senderDisplayName date:(NSDate *)date
{
[self addMessagewithId:senderId name:senderDisplayName date:date andText:text inArray:_messages inGroup:nil];
NSDateFormatter *dateF = [[NSDateFormatter alloc] init];
dateF.dateFormat= @"yyyy-MM-dd hh:mm:ss zzzz";
NSString *dateStr = [dateF stringFromDate:date];
NSDictionary *mdata = @{@"text": text, @"senderId":senderId, @"displayName": senderDisplayName, @"date":dateStr};
// Push data to Firebase Database
[[[_rootRef child:@"messages"] childByAutoId] setValue:mdata];
[self finishSendingMessageAnimated:NO];
_isTyping =false;
[self sendIsTyping];
}
-(void)addMessagewithId:(NSString*) senderId name:(NSString*) name date:(NSDate*)date andText:(NSString*) text inArray:(NSMutableArray*)array inGroup:(dispatch_group_t)group1
{
JSQMessage* message = [[JSQMessage alloc] initWithSenderId:senderId senderDisplayName:name date:date text:text];
[array addObject:message];
if (group1) {
dispatch_group_leave(group1);
}
}
但是调用之后
[self finishSendingMessageAnimated:NO];
文本视图开始冻结,光标停留在文本结束的位置。随着用户发送更多消息,此冻结时间会增加。请帮忙
我的代码中的问题是在调用方法后
[[[_rootRef child:@"messages"] childByAutoId] setValue:mdata];
it was again reloading all the collectionview as expected from FIRDataEventTypeValue . So I put an array like this :
[[[_rootRef child:@"messages"] queryOrderedByKey] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
for (FIRDataSnapshot *child in snapshot.children) {
if ([_arrSnap containsObject:child.key]) {
return;
}
else
{
[_arrSnap addObject:child.key];
//do rest of your coding here
}
}
}
所以我的 collectionview 的重新加载停止了,所有额外的代码执行也停止了。
也感谢@danielleonard 的回复。它引导我找到了这个解决方案。
发送 2-3 条消息后,我的 TextView 卡住了。我的 iOS 版本是 10.2.1,测试设备是 iPhone 6Plus,JSQMessagesViewController 版本是 7.3.4,代码在 Obj-C 中。我已经实现了以下方法:
-(void)didPressSendButton:(UIButton *)button withMessageText:(NSString *)text senderId:(NSString *)senderId senderDisplayName:(NSString *)senderDisplayName date:(NSDate *)date
{
[self addMessagewithId:senderId name:senderDisplayName date:date andText:text inArray:_messages inGroup:nil];
NSDateFormatter *dateF = [[NSDateFormatter alloc] init];
dateF.dateFormat= @"yyyy-MM-dd hh:mm:ss zzzz";
NSString *dateStr = [dateF stringFromDate:date];
NSDictionary *mdata = @{@"text": text, @"senderId":senderId, @"displayName": senderDisplayName, @"date":dateStr};
// Push data to Firebase Database
[[[_rootRef child:@"messages"] childByAutoId] setValue:mdata];
[self finishSendingMessageAnimated:NO];
_isTyping =false;
[self sendIsTyping];
}
-(void)addMessagewithId:(NSString*) senderId name:(NSString*) name date:(NSDate*)date andText:(NSString*) text inArray:(NSMutableArray*)array inGroup:(dispatch_group_t)group1
{
JSQMessage* message = [[JSQMessage alloc] initWithSenderId:senderId senderDisplayName:name date:date text:text];
[array addObject:message];
if (group1) {
dispatch_group_leave(group1);
}
}
但是调用之后
[self finishSendingMessageAnimated:NO];
文本视图开始冻结,光标停留在文本结束的位置。随着用户发送更多消息,此冻结时间会增加。请帮忙
我的代码中的问题是在调用方法后
[[[_rootRef child:@"messages"] childByAutoId] setValue:mdata];
it was again reloading all the collectionview as expected from FIRDataEventTypeValue . So I put an array like this :
[[[_rootRef child:@"messages"] queryOrderedByKey] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
for (FIRDataSnapshot *child in snapshot.children) {
if ([_arrSnap containsObject:child.key]) {
return;
}
else
{
[_arrSnap addObject:child.key];
//do rest of your coding here
}
}
}
所以我的 collectionview 的重新加载停止了,所有额外的代码执行也停止了。
也感谢@danielleonard 的回复。它引导我找到了这个解决方案。