我刚刚尝试使用 JSQMessagesViewController
在我的 Xamarin.iOS
应用中实现 LocationMediaItem
。一切都很顺利,唯一的问题是应该显示位置的 UICollectionView
单元格永远停留在加载状态,并且 map 从未真正显示。
以下是我如何在 C# 中制作 locationMediaItem
的一些代码:
var locationMediaItem = new LocationMediaItem(new CLLocation(latitude, longitude));
if (ChatDB.Messages[indexPath.Row].user_id == SenderId)
{
locationMediaItem.AppliesMediaViewMaskAsOutgoing = true;
return JSQMessagesViewController.Message.Create(ChatDB.Messages[indexPath.Row].user_id, User.Instance.name, locationMediaItem);
}
这是我的意思的图像:
所以 JSQMessagesViewController
知道我希望它显示 map View ,但它永远不会停止加载,我不明白为什么。
希望有人能帮忙。
最佳答案
遇到了和你一样的问题,并且能够解决它。
诀窍是不要在 LocationMediaItem 构造函数中设置位置,将其保留为 null,然后使用 SetLocation 方法接收位置和句柄作为参数。
var itemLoationItem = new LocationMediaItem ();
itemLoationItem.AppliesMediaViewMaskAsOutgoing = true;
Messages.Add (Message.Create (SenderId, SenderDisplayName, itemLoationItem));
itemLoationItem.SetLocation (new CLLocation (lat, long), HandleLocationMediaItemCompletionBlock);
在句柄中只需重新加载数据
void HandleLocationMediaItemCompletionBlock ()
{
this.CollectionView.ReloadData ();
}
注意:避免在 GetMessageData
中创建 Message 对象,因为每次重新加载 Collectionview 时都会调用此方法。您应该在接收消息或发送消息时处理消息创建并将其添加到消息集合中,然后在此方法中您只需从集合中返回对象。
public override IMessageData GetMessageData (MessagesCollectionView collectionView, NSIndexPath indexPath)
{
return Messages [indexPath.Row];
}
关于c# - 在 JSQMessagesViewController 中显示 LocationMediaItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42314143/