0

我的应用程序出现了一些问题,我目前正在使用 WEPopover 库(ARCified)来创建一些自定义弹出框。但是,每次我呈现一个弹出窗口并且它的相应视图(由一个视图和一个填充有数组的表格视图组成)时,仪器中的分配都会增长,即使我只是一次又一次地重新添加相同的弹出窗口它会增长。我错过了什么,或者这是正常行为,请参见下面的代码。我应该改为使表格视图变弱还是什么?

ThemesPopOverViewController.h

#import <UIKit/UIKit.h>
#import "AppDelegate.h"


@interface ThemesPopOverViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>{
    NSArray *themes;
}
@property (nonatomic, retain) UITableView *tableView;
@end

ThemesPopOverViewController.m

#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];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    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];
}

-(void) viewDidAppear:(BOOL)animated{
    int item = [themes indexOfObject:theDelegate.codeView.currentTheme];
    NSIndexPath *indexPath = [NSIndexPath indexPathForItem:item inSection:0];
    [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
}

- (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.codeView setNeedsDisplay];
    themes = nil; 
    [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];

        newView = nil;
    }else{
        [self removePop];
    }
}

以及“theDelegate”中用于消除弹出框的 remove 方法:

-(void) removePop{

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

基线 = 没有弹出框,Heapshot1 = 添加弹出框,Heapshot2 = 弹出框已解除,Heapshot3 = 再次添加相同的弹出框,Heapshot4 = 弹出框已解除。

Snapshot    Timestamp   Heap Growth # Persistent
- Baseline -    00:07.464.624   1.59 MB 25041
Heapshot 1  00:11.759.060   50.34 KB    787
Heapshot 2  00:16.278.744   0 Bytes 0
Heapshot 3  00:24.312.874   30.39 KB    608
Heapshot 4  00:28.361.293   288 Bytes   7
4

1 回答 1

0

在 Your SettingsAct button~action~method 中执行这样的代码

 if (self.popoverController)
{
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController = nil;
}
else
{
    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];
}

这对我来说可以 :)

于 2013-09-17T08:16:37.500 回答