首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在LocationMediaItem中显示JSQMessagesViewController

在LocationMediaItem中显示JSQMessagesViewController
EN

Stack Overflow用户
提问于 2017-02-18 10:50:22
回答 1查看 161关注 0票数 2

我刚刚尝试使用LocationMediaItem在我的Xamarin.iOS应用程序中实现JSQMessagesViewController。一切都进行得很好,唯一的问题是应该显示位置的UICollectionView单元永远在加载时被卡住,而地图永远不会被实际显示。

下面是我如何在locationMediaItem中使用C#编写的一些代码:

代码语言:javascript
复制
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知道我希望它显示一个地图视图,但它从未停止加载,我也不知道为什么。

希望有人能帮忙。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-19 21:45:37

和你有同样的问题并能让它发挥作用。

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

代码语言:javascript
复制
var itemLoationItem = new LocationMediaItem ();
itemLoationItem.AppliesMediaViewMaskAsOutgoing = true;
Messages.Add (Message.Create (SenderId, SenderDisplayName, itemLoationItem));
itemLoationItem.SetLocation (new CLLocation (lat, long), HandleLocationMediaItemCompletionBlock);

在句柄中重新加载数据

代码语言:javascript
复制
void HandleLocationMediaItemCompletionBlock ()
{
    this.CollectionView.ReloadData ();
}

注意事项:避免在GetMessageData中创建消息对象,因为每次重新加载集合视图时都会调用此方法。您应该在接收消息或发送消息时处理消息创建,并将其添加到消息集合中,然后在此方法中只需从集合中返回对象。

代码语言:javascript
复制
public override IMessageData GetMessageData (MessagesCollectionView collectionView, NSIndexPath indexPath)
{
    return Messages [indexPath.Row];
}

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42314143

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档