2017-02-18 27 views
2

我剛剛嘗試在Xamarin.iOS應用中使用JSQMessagesViewController實施LocationMediaItem。一切工作正常,唯一的問題是,應該顯示位置的UICollectionView單元永久停留在加載狀態,並且地圖從未實際顯示。在JSQMessagesViewController中顯示LocationMediaItem

下面是一些代碼,我如何讓用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知道我希望它顯示一個地圖視圖,但它永遠不會停止加載,我不明白爲什麼。

希望有人能幫忙。

+0

會發生什麼? – apineda

+0

我試過,但沒有成功,我也確保lat和lng不爲空 – Florensvb

回答

2

與您有同樣的問題,並能夠使其工作。

訣竅是不在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消息對象調用此方法每次的CollectionView重新加載時間。您應該在接收消息或發送消息時處理消息創建,並將其添加到消息集合中,然後在此方法中,您只需從集合中返回對象。創建LocationMediaItem對象時,當你把latitud固定和經度

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

Image showing location

+0

Dude!非常感謝你的回答,我一直在等待有人這麼久哈哈。我剛剛嘗試過你的建議,但不幸的是沒有結果。這是我如何適應我的代碼: 'locationMediaItem.SetLocation(新CLLocation(緯度,經度),委託 \t \t \t \t \t \t { \t \t \t \t \t \t \t collectionView.ReloadData(); \t \t \t \t \t \t});' 我在'collection.reload'處添加了一個突破點,它實際上被調用了,但是地圖沒有出現... 我還沒有實現你的建議,不是每次都創建一個新的JSQMessage。我一定會這樣做,但我懷疑它可能是我問題的根源? – Florensvb

+0

事實上,一旦我按照你的建議實施了所有的改變,它就起作用了!再次感謝 – Florensvb

相關問題