【发布时间】:2010-02-03 05:31:39
【问题描述】:
在objective-c (cocoa touch) 中,我有一系列UIViewController 可以在它们之间切换。
- (void)switchViews:(id)sender
{
UIButton *button = (UIButton *)sender;
UIViewController *nextViewController;
int tag = button.tag;
switch (tag)
{
// -- has already been created
case kFinancialButton:
nextViewController = financials;
break;
case kSocialButton:
if (social == nil)
{
SocialViewController *socialViewController = [[SocialViewController alloc] initWithNibName:@"SocialViewController" bundle:nil];
social = socialViewController;
[socialViewController release];
}
nextViewController = social;
break;
case kTicketingButton:
if (ticketing == nil)
{
TicketingViewController *ticketingViewController = [[TicketingViewController alloc] initWithNibName:@"TicketingViewController" bundle:nil];
ticketing = ticketingViewController;
[ticketingViewController release];
}
nextViewController = ticketing;
break;
}
///////
------> // -- [button/nextViewController release]????
///////
[self setActiveButton:button];
}
如您所见,我将其中一个视图控制器分配给“nextViewController”。我想知道的是我是否需要释放这个“本地”变量,或者是否可以不理会,因为它只是指向我的一个视图控制器(我在 dealloc 中释放)。我认为不需要发布“标签”,因为它是“原始”,对吗?按钮呢?我不太明白应该和不应该明确发布什么,所以也许我过于谨慎了。提前致谢。
【问题讨论】:
标签: objective-c iphone cocoa-touch xcode