我應該如何將一個字符串傳遞給在選中tableviewcell時被推入的視圖控制器。 我應該在視圖控制器中創建一個自定義的init方法嗎?例如[[myvc alloc]initWithURL:...]
設置屬性?例如[myvc setURL:...]
或myvc.url = ...
或者只是創建一個自定義的方法? [myvc setLoadingURL:...]
將字符串從tableviewcontroller傳遞給導航堆棧中的viewcontroller
0
A
回答
0
我們實際上已經完成了這兩種方式(使用init和property)。我發現該屬性是最好的方法,因爲如果ViewController是由InterfaceBuilder創建的,則可能不會調用自定義init方法。隨着財產,你總是被迫設置它,如果你想使用它。
只需$ 0.02,
-dan
0
任何這些解決方案都是可以接受的。我想如果你只是傳遞一個字符串,那麼一個屬性就足夠了。我一直在爲更復雜的對象保存init方法。這裏有一個我最近的「高分」表格,當你挖一排,顯示在堆棧上的輪廓圖:
ProfileController *profileController = [[ProfileController alloc] initWithNibName:@"ProfileController" bundle:nil];
// pass the controller the player object
[profileController showProfile:player];
// show it by pusing it on the stack
[self pushViewController:profileController animated:YES];
[profileController release];
我可以創建另一個初始化像
ProfileController *profileController = [[ProfileController alloc] initWithPlayer:player];
代替。這看起來更優雅一些,但正如我所說,你的任何方法都可以。
相關問題
- 1. 多次將相同的TableViewController導入導航堆棧
- 2. 在導航卸下的ViewController堆棧
- 3. 如何將字符串從一個tableViewController傳遞到使用導航的其他tableViewController
- 4. 如何將字符串從一個viewcontroller傳遞給另一個?
- 5. 加載UIView到導航堆棧不傳遞字符串到新視圖
- 6. 如何在將數據推送到導航堆棧之前將數據傳遞給viewcontroller並加載它?
- 7. 將文本從UITextView傳遞到不同ViewController中的字符串
- 8. 從文本字段以字符串,並將它傳遞給以前的viewController
- 9. 反轉從堆棧中的字符串
- 10. 從堆棧導航到CDB/WinDbg中的託管堆棧中的堆棧幀
- 11. 字符堆棧,字符串堆棧,整數堆棧,整數數組堆棧等
- 12. 從AppDelegate將NSDictionary傳遞給ViewController
- 13. 將NSString從ViewController傳遞給NSObject
- 14. 從導航堆棧中刪除網頁
- 15. 嘗試將ViewController中的字符串傳遞給NSObject中的字符串..但它無法工作
- 16. 將字符串傳遞給URL。
- 17. 將字符串[]傳遞給javascript
- 18. 將連接字符串傳遞給dll?
- 19. 將值傳遞給查詢字符串
- 20. 將字符串傳遞給函數
- 21. 將查詢字符串傳遞給rDirectory
- 22. 將字符串傳遞給float數組?
- 23. 將字符串傳遞給jquery函數
- 24. 將字符串傳遞給make文件
- 25. 將字符串傳遞給onItemClick函數
- 26. 將字符串變量傳遞給marquee
- 27. 將字符串傳遞給dll
- 28. 將字符串傳遞給TableAdapter
- 29. 將查詢字符串傳遞給silverlight
- 30. 將字符串傳遞給textview