我正在编写一个仅在 popOver 中显示菜单(由 tableView 组成)的函数。
这是源代码:
-(void)pushSearch:(NSString *)option type:(int)optionType
{
searchNav = [[iNavigation alloc] initWithNibName:@"iNavigation" bundle:nil] ;
//This is the UIViewController with the tableView
[searchNav setSearchMode:optionType];
searchNav.view.frame =CGRectMake(0,0,300,600);
NSLog(@"Retain Count: %d",[searchNav retainCount]);
//此时retain count为1
if ([pop isPopoverVisible])
{
[pop dismissPopoverAnimated:YES];
[pop release];
}
pop = [[UIPopoverController alloc] initWithContentViewController:searchNav];
NSLog(@"Retain Count: %d",[searchNav retainCount]);
//At this point retain count is 2
[pop presentPopoverFromRect:btnMenu.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[pop setPopoverContentSize:CGSizeMake(350,600)];
NSLog(@"Retain Count: %d",[searchNav retainCount]);
//At this point retain count is 5!!!
[searchNav release];
}
我遇到的问题是用于加载 tableview 的内存永远不会被释放。我的应用程序在内存中不断增长,直到崩溃。
为什么如果我只为 searchNav 分配一次,在将其分配给 popOver 后,retin 计数为 5?
请问有什么帮助吗?