2010-05-24 53 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]; 

代替。这看起来更优雅一些,但正如我所说,你的任何方法都可以。

相关问题