本文介绍了在 JSQMessagesViewController 中显示 LocationMediaItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚尝试使用 JSQMessagesViewController 在我的 Xamarin.iOS 应用程序中实现 LocationMediaItem.一切都很好,唯一的问题是应该显示位置的 UICollectionView 单元格永远卡在加载中,并且地图从未真正显示过.

I have just tried implementing the LocationMediaItem in my Xamarin.iOS app using JSQMessagesViewController. Everything worked out fine, only problem is that the UICollectionView cell which is supposed to show the location is stuck on loading forever and the map is never actually being displayed.

这是我如何在 C# 中制作 locationMediaItem 的一些代码:

Here's some code how I make the 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);
    }

这是我的意思的图像:

所以 JSQMessagesViewController 知道我想让它显示地图视图,但它永远不会停止加载,我不知道为什么.

So the JSQMessagesViewController knows I want it to display a map view, but it never stops loading and I can't figure out why.

希望有人能帮忙.

推荐答案

遇到了与您相同的问题,并且能够使其正常工作.

Was having the same issue as you and was able to make it work.

诀窍是不要在 LocationMediaItem 构造函数上正确设置位置,将其保留为空,然后使用 SetLocation 方法接收位置和句柄作为参数.

The trick was not to set the location right on the LocationMediaItem constructor, leave it null then use the method SetLocation which receives the location and a handle as parameters.

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 时都会调用此方法.您应该在接收消息或发送消息时处理消息创建并将其添加到消息集合中,然后在此方法中您只需从集合中返回对象.

Note: Avoid creating the Message object in GetMessageData as this method is called every time the Collectionview is reloaded. You should handle the Message creation when receiving the message or when sending it and add it to the collection of messages then in this method you just return the object from the collection.

public override IMessageData GetMessageData (MessagesCollectionView collectionView, NSIndexPath indexPath)
{
    return Messages [indexPath.Row];
}

这篇关于在 JSQMessagesViewController 中显示 LocationMediaItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 22:12