2010-05-24 104 views

回答

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]; 

代替。這看起來更優雅一些,但正如我所說,你的任何方法都可以。

相關問題