我刚刚尝试实施LocationMediaItem
in my Xamarin.iOS
应用程序使用JSQMessagesViewController
。一切都很顺利,唯一的问题是UICollectionView
应该显示位置的单元格永远停留在加载状态,并且地图从未真正显示。
这是我如何制作的一些代码locationMediaItem
in 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);
}
这是我的意思的图像:
So the JSQMessagesViewController
知道我希望它显示地图视图,但它永远不会停止加载,我不明白为什么。
希望有人可以帮忙。
遇到了与您相同的问题,并且能够使其工作。
诀窍是不要在 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 ();
}
Note: 避免创建 Message 对象GetMessageData
因为每次重新加载 Collectionview 时都会调用此方法。您应该在接收消息或发送消息时处理消息创建并将其添加到消息集合中,然后在此方法中您只需从集合中返回对象。
public override IMessageData GetMessageData (MessagesCollectionView collectionView, NSIndexPath indexPath)
{
return Messages [indexPath.Row];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)