我刚刚尝试使用LocationMediaItem在我的Xamarin.iOS应用程序中实现JSQMessagesViewController。一切都进行得很好,唯一的问题是应该显示位置的UICollectionView单元永远在加载时被卡住,而地图永远不会被实际显示。
下面是我如何在locationMediaItem中使用C#编写的一些代码:
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知道我希望它显示一个地图视图,但它从未停止加载,我也不知道为什么。
希望有人能帮忙。
发布于 2017-02-19 21:45:37
和你有同样的问题并能让它发挥作用。
诀窍是不要在LocationMediaItem构造函数上设置位置,将其保留为空,然后使用接收位置和句柄作为参数的方法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中创建消息对象,因为每次重新加载集合视图时都会调用此方法。您应该在接收消息或发送消息时处理消息创建,并将其添加到消息集合中,然后在此方法中只需从集合中返回对象。
public override IMessageData GetMessageData (MessagesCollectionView collectionView, NSIndexPath indexPath)
{
return Messages [indexPath.Row];
}

https://stackoverflow.com/questions/42314143
复制相似问题