【发布时间】:2011-09-25 21:29:10
【问题描述】:
我现在已经花了几天时间试图弄清楚发生了什么,而且我这辈子看不到自己做错了什么。当用户触摸屏幕上的一个点时,我会弹出一个 UIPopover。弹出框有一个选项卡控制器和表格视图,用于显示有关该点的信息。但是当弹出窗口被解除时,它会崩溃并声称: -[UIAnimator removeAnimationsForTarget:]: 消息发送到释放的实例
这是加载视图控制器的代码:
MyViewController *popView = [[MyViewController alloc] init];
myPop = [[UIPopoverController alloc] initWithContentViewController:pop];
[popView release];
myPop.delegate = self;
[airportPop setPopoverContentSize:popView.view.frame.size];
[airportPop presentPopoverFromRect:CGRectMake(location.x,location.y,1,1) inView:self.mainView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
- (void)dismissPopover {
if( myPop != nil ) {
[myPop dismissPopoverAnimated:YES];
[myPop.delegate popoverControllerDidDismissPopover:airportPop];
}
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
[myPop release];
myPop = nil;
}
实际的 MyViewController 只是一个带有(为简洁起见)init 的 UIViewController:
- (id)init
{
self = [super init];
//create a newview
self.view = popView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, POPUP_WIDTH, POPUP_HEIGHT)];
[popView release];
topBar = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, POPUP_WIDTH, 30)];
....
[popView addSubview:topBar];
[topBar release];
//create a table view
self.table = [[UITableView alloc] initWithFrame:CGRectMake(0, 30, POPUP_WIDTH, POPUP_HEIGHT-30-49)];
table.delegate = table.dataSource = self;
....
//create a tab bar
tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(0, POPUP_HEIGHT-49, POPUP_WIDTH, 49)];
tabBar.delegate = self;
[popView addSubview:tabBar];
[popView addSubview:table];
[tabBar release];
[table release];
return( self );
}
Dealloc 只不过是 [super dealloc],因为一切本质上都归视图所有,视图控制器会处理它。当 myPop 被释放时,在 DidDismissPopover 中,视图也被释放,所以这似乎工作正常。但不久之后,我遇到了崩溃。
当弹出窗口消失时,我需要做一些特殊的事情来丢弃标签视图或表格视图吗?
我正在对表格中的单元格使用自动释放,我应该停止这样做吗?
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
提前感谢您的帮助!!!任何想法都非常感谢!
-凯文
【问题讨论】:
标签: objective-c ios ipad memory-management uipopover