开发者

Memory Management with UIPopoverController

开发者 https://www.devze.com 2023-03-16 09:38 出处:网络
I wanted to double check that I was doing correct memory management.Is this correct?Do I have the correct amount of releases.

I wanted to double check that I was doing correct memory management. Is this correct? Do I have the correct amount of releases.

In my .h file:

UITableView *_sortOrderTableView;
@property (nonatomic, retain) UITableView *SortOrderTableView;

In my .m file:

In dealloc

 [_sortOrderTableView release];

My code that presents the popover is this:

- (IBAction)sortButtonOrderPressed:(id)sender {
    UIViewController *sortOrderController = [[UIViewController alloc] init];

    self.SortOrderTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
self.SortOrderTableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"App_Background.png"]];
self.SortOrderTableView.bounces = NO;
self.SortOrderTableView.scrollEnabled = NO;
    sortOrderController.view = self.SortOrderTableView;
    sortOrderController.contentSizeForViewInPopover = C开发者_如何学CGSizeMake(200, 100);
    self.SortOrderTableView.delegate = self;
    self.SortOrderTableView.dataSource = self;

    self.SortPopover = [[UIPopoverController alloc] initWithContentViewController:sortOrderController];
    [self.SortPopover presentPopoverFromRect:_sortButtonOrder.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

    [self.SortOrderTableView release];
    [sortOrderController release];
}


Remove [self.SortOrderTableView release];, it should be [_sortOrderTableView release]; or self.SortOrderTableView = nilanyway, but you're already calling that in your dealloc method, so there is no need to release it here. If you want to release it though, use self.SortOrderTableView = nil.

Apart from that you will also have to release your SortPopover's instance variable in your dealloc method.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号