在兩個視圖控制器之間實現segue時如何使用segue對象更改目標視圖控制器的屬性?文檔說這可以在prepareForSegue:sender:方法中完成。我嘗試過,但不是沒有成功iOS 5 segue實現
6
A
回答
13
說不上來,如果你仍然需要一個答案,但它是這樣一個孤獨的職位,如果我是正確的,這並不NDA下摔倒下去。如果我錯了,請將我的答案遺忘一下,所以我們走了:我剛剛完成了一些使用你需要的東西。這是代碼爲我的作品:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"relevantSegueIdentifier"])
{
// [segue destinationViewController] is read-only, so in order to
// write to that view controller you'll have to locally instantiate
// it here:
ViewController *upcomingViewController = [segue destinationViewController];
// You now have a solid reference to the upcoming/destination view
// controller. Example use: Allocate and initialize some property of
// the destination view controller before you reach it and inject a
// reference to the current view controller into the upcoming one:
upcomingViewController.someProperty = [[SomePropertyClass alloc] initWithString:@"Whatever!"];
upcomingViewController.initialViewController = [segue sourceViewController];
// Or, equivalent, but more straightforward:
//upcomingViewController.initialViewController = self;
}
}
這假定兩個someProperty和initialViewController合成目標視圖控制器的存取。希望這可以幫助!
5
我寫了一個教程,給出了將信息傳遞給新場景以及使用委託從場景返回信息的代碼示例,因此請檢查出它應該解決您的問題。 iOS 5 Storyboard: How To use Segues, Scenes and Static Content UITableViews
+0
我在閱讀這篇博文之前閱讀博客..感謝您的博客。 – thesummersign
0
我拍了一個關於這個話題的視頻。我希望它有幫助。 http://full.sc/17yKkZF
0
我在源視圖控制器使用的是:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UIViewController *upcomingViewController = [segue destinationViewController];
upcomingViewController.view.tag = [[segue identifier] hash];
}
然後在目的地視圖控制器我使用(在viewDidAppear使用例如)
if(self.view.tag == [@"MySeqgueIdentifier" hash])
{
// Do something here...
}
這是很酷的,因爲你不必創建任何屬性等等,並且所有的東西都可以在界面構建器中正常工作。
相關問題
- 1. 推iOS 5中的segue不工作
- 2. 通過代碼實現Segue實施
- 3. 如何在ios 5中實現RETWEET?
- 4. 如何實現此segue/view外觀?
- 5. ios transitiondelegate與segue
- 6. Double Segue IOS
- 7. ios segue「取消」
- 8. iOS 4和iOS 5上APNS的實現有什麼不同嗎?
- 9. iOS Segue ViewController緩存
- 10. MVC 5 EnumDropDownListFor實現
- 11. 如何實現自定義segue動畫?
- 12. iOS Detect從push segue展開segue
- 13. iOS CollectionViewCell展開Segue
- 14. iOS push style segue transition
- 15. iOS:故事板Segue
- 16. iOS 5 NSURLConnectionLoader Segue之後的線程行爲
- 17. 無法在iOS 5的其他課程中執行segue?
- 18. 使用segue ios推送不同的視圖控制器5
- 19. 的iOS 5 - 從一個TableViewController Segue公司到另一個TableViewController
- 20. iOS NSCoding實現
- 21. Swift iOS - unwind segue崩潰
- 22. iOS segue執行兩次
- 23. HTML 5參考實現
- 24. 實現與laravel加入5
- 25. EcmaScript 5瀏覽器實現
- 26. HTML 5 Panotour Pro實現
- 27. 有沒有辦法在iOS 5中實現可縮放的UIPageViewController?
- 28. 在iOS 5中使用addbarViewbarControl在菜單欄底部實現MenBar
- 29. 在iOS 5的iPhone應用程序中實現聊天功能?
- 30. 實現MapKit iOS Xcode
它屬於NDA,但在3天內它不會正式發佈在十月十四日,但我喜歡你的答案+1 –
我試過你說的,但我的'destinationViewController'上的屬性不更新。有什麼建議? – Francesco
我認爲你使用目標視圖控制器的綜合訪問器(而不是私有ivar),並且視圖控制器已經在應用程序設置期間實例化(例如,具有實際視圖控制器的故事板放置在它中間,它們之間的所有實例化應用程序發射)。在這種情況下,它應該工作。這可能就像系統不知道你的特定目標。視圖控制器類。在我的例子中,類ViewController是UIViewController的一個子類,在@implementation之前我做了一些類似'#import「ViewController.h」'的操作。它可能是這些東西之一嗎? – DarqueSandu