c# - 在 JSQMessagesViewController 中显示 LocationMediaItem

标签 c# ios xamarin.ios jsqmessagesviewcontroller

我刚刚尝试使用 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);
    }

这是我的意思的图像:

Here

所以 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];
}

Image showing location

关于c# - 在 JSQMessagesViewController 中显示 LocationMediaItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42314143/

相关文章:

iphone - IOS 5 TWTweetComposeViewController 重复推文

xamarin - Web View 中的 Cookie xamarin iOS

c# - 为什么在 Parallel.ForEach 中每个线程会多次调用 localInit Func

如何使用 AsParallel()/Parellel.ForEach() 的 C# 编码指南

iOS 8 欧洲/莫斯科时区问题

ios - UIButton不会根据内部文本的长度垂直增长

ios - 完成 iOS 后台任务,将其移动到前台

c# - XAML 文件是否可移植到 Xamarin Macintosh?

c# - 从列表中指定索引处删除元素的有效方法

c# - 如何在 C# 中使用带有参数化查询的 SqlDataReader?