2015-04-21 47 views
-3

我想繼續更新userLocation每0.5s從viewController anotherViewController!我試過使用segue,但只更新一個,任何人都知道另一種方法或如何?從另一個視圖控制器更新位置

謝謝!

+0

張貼您的代碼開始 – KenD

+0

請在您的文章中包含[您嘗試過](http://mattgemmell.com/what-have-you-tried/)。 – milo526

回答

0

當然。

創建一個協議。我們稱之爲MyLocationDelegateProtocol。

給它一個獲取位置更新的方法。

讓您的anotherViewController實現該方法,並將MyLocationDelegateProtocol添加到類定義中。 (這些步驟可以稱爲「使類符合MyLocationDelegateProtocol」。)

給予將發送位置更新的視圖控制器一個locationDelegate屬性。當你創建視圖控制器時,將它的locationDelegate屬性設置爲你的anotherViewController。

編寫位置方法,以便它們檢查locationDelegate屬性是否爲零。如果不是零,則使用MyLocationDelegateProtocol中定義的消息將位置消息發送到locationDelegate。

相關問題