ios - 当 Controller 从 View 中删除时,如何从 PopOverViewController 释放内存,ARC

标签 ios uitableview automatic-ref-counting uipopovercontroller

嗨,我有一个带有表格 View 的 popoverviewcontroller。每次我按下按钮查看弹出窗口时,都会分配一些内存(1024)。如果我多次按下它,分配就会不断增加。由于应用程序是用 ARC 编写的,我认为这将由自动处理。我如何确保我的弹出窗口在删除时确实删除了所有分配的数据,代码附在下面:

//
//  SettingPopOverViewController.m
//  CodeFriend
//
//  Created by Exjobb on 5/22/13.
//  Copyright (c) 2013 davidkarlsson. All rights reserved.
//

#import "ThemesPopOverViewController.h"

@interface ThemesPopOverViewController ()

@end

@implementation ThemesPopOverViewController
@synthesize tableView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {


        themes = [[NSArray alloc] initWithObjects:kRegexHighlightViewThemeArray];
        self.tableView = nil;
        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(20, 0, self.view.frame.size.width - 40, 350)];
        [self.tableView setBackgroundColor:[UIColor clearColor]];
        [self.tableView setDelegate:self];
        [self.tableView setDataSource:self];
        [self.view addSubview:self.tableView];
        int item = [themes indexOfObject:theDelegate.codeView.currentTheme];
        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:item inSection:0];
        [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];

    }

    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;    //count of section
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //NSLog(@"%d",themes.count);
    return [themes  count];    //count number of row from counting array hear cataGorry is An Array
}



- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *MyIdentifier = @"MyIdentifier";

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:MyIdentifier];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:MyIdentifier];

        UIView *bgColorView = [[UIView alloc] init];
        [bgColorView setBackgroundColor:[UIColor colorWithRed:25/255.0f green:185/255.0f blue:152/255.0f alpha:1.0f]];
        [cell setSelectedBackgroundView:bgColorView];
    }
    [cell.textLabel setFont:[UIFont fontWithName:@"Helvetica" size:16]];
    cell.textLabel.text = [themes objectAtIndex: indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"%d", indexPath.row);
    [theDelegate.codeView setHighlightThemeFromString:[themes objectAtIndex:indexPath.row]];
    [theDelegate removePop];

}

@end

我正在展示流行音乐:

-(void) settingAct:(UIButton *)sender{
    if (!popover) {
        ThemesPopOverViewController *newView = [[ThemesPopOverViewController alloc] initWithNibName:@"SettingPopOverViewController" bundle:[NSBundle mainBundle]];
        self.popover = [[WEPopoverController alloc] initWithContentViewController:newView];
        [self.popover setContainerViewProperties:[self improvedContainerViewProperties]];
        [self.popover setPopoverContentSize:CGSizeMake(128, 360)];
        [self.popover presentPopoverFromRect:CGRectMake(sender.center.x+12, sender.center.y, 0, 20)
                                      inView:self.window.rootViewController.view
                    permittedArrowDirections:(UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown|
                                              UIPopoverArrowDirectionLeft|UIPopoverArrowDirectionRight)
                                    animated:YES];


    }else{
        [self removePop];
    }
}

仅使用以下方法即可删除弹出窗口:

-(void) removePop{

    [self.popover dismissPopoverAnimated:YES];
    self.popover = nil;
}

最佳答案

如果我记得的话,WePopOver 尚未 ARCified。有一个 Arc 版本:this link 。我不确定,但这可能是问题所在。您可以做的另一件事是在所有相关对象子类中的 dealloc 方法中添加一条日志消息,以便您可以观察弹出窗口关闭时哪些对象未释放。

关于ios - 当 Controller 从 View 中删除时,如何从 PopOverViewController 释放内存,ARC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16997220/

相关文章:

iphone - 向下滚动时在 HTML5 移动应用程序 (PhoneGap) 中制作动画图像,例如 Google Plus iPhone 应用程序?

iOS - 在越狱设备上访问沙箱外的文件系统

ios - 选择自定义 UITableViewCell 按钮 - 重新加载数据

iPhone:NSdecimalNumber 转换问题

objective-c - -dealloc 对于从 KVO 取消注册来说太晚了

iphone - 通过单击 UITableViewCell 将 UIWebView 推送到 UINavigationController 后未加载

ios - 通过 APNS 在有效负载中发送的数据

ios - 如何在 ios 中舍入表格 View 单元格

ios - 如何在点击另一行时取消选择一行?

objective-c - DCRoundSwitch 在使用 ARC 时给出 EXC_BAD_ACCESS