视图框架未释放其内存

时间:2017-03-15 20:06:09

标签: ios objective-c iphone uitabbarcontroller

我无法纠正

中出现的情况
customTabView.view.frame = CGRectMake(0, self.view.frame.size.height-49, self.view.frame.size.width, 49);

其中,每次分配的内存,在解除视图后不释放。

嗯,情况是,我创建了一个简单的登录界面rootviewcontroller,然后通过一个按钮(登录按钮)呈现tabviewcontroller其中,我在tabviewcontroller上添加了一个视图作为子视图在那个子视图中有四个按钮,通过委托我控制tabIndex,一切正常,但是当我检查泄漏的内存时,上面的视图。帧保持内存。 我发布了图片,请看一下,

enter image description here

这是我的带有用户标签栏的TabView控制器。

enter image description here

任何帮助都会很明显。

更新:

这是我的完整代码。

从登录页面:

- (IBAction)clickLoginBtnAction:(id)sender {


    tabControler = [self.storyboard instantiateViewControllerWithIdentifier:@"TabBarController"];

    [self presentViewController:tabControler animated:YES completion:nil];

}

来自Tabbar控制器:

#import "TabBarController.h"

@interface TabBarController ()<TabBarIndexProtocol>{

//    CustomTabViewController *customTabView;
}

@property (strong) CustomTabViewController *customTabView;



@end

@implementation TabBarController

@synthesize customTabView;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    customTabView = [self.storyboard instantiateViewControllerWithIdentifier:@"CustomTabViewController"];
    self.tabBar.hidden = YES;
    [self frameCustomTabViewOnTabBar];
    customTabView.tabBarIndexDelegate = self;

}

-(void)viewDidDisappear:(BOOL)animated{

//    customTabView.view.frame = nil;
}

// For Screen Rotation

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
    [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {

        [self frameCustomTabViewOnTabBar];

    }];
}

-(void)frameCustomTabViewOnTabBar{

    customTabView.view.frame = CGRectMake(0, self.view.frame.size.height-49, self.view.frame.size.width, 49);
    [self.view addSubview:customTabView.view];
}


# pragma mark - TabBarIndexProtocol from CustomTabBarClass

-(void)tabBarIndexSelected :(int)tabNumber{

    NSLog(@"%d",(int)tabNumber);

    [self setSelectedIndex:tabNumber];
}

在我的CustomeTab.h文件中:

#import <UIKit/UIKit.h>

@protocol TabBarIndexProtocol <NSObject>

@required

-(void)tabBarIndexSelected :(int)tabNumber;

@end

@interface CustomTabViewController : UIViewController

@property(weak) id <TabBarIndexProtocol> tabBarIndexDelegate;

@end

并从其.m文件

#import "CustomTabViewController.h"

@interface CustomTabViewController ()

@end

@implementation CustomTabViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (IBAction)tabNumberOne:(id)sender {

    [self.tabBarIndexDelegate tabBarIndexSelected:0];
}

- (IBAction)tabNumberTwo:(id)sender {

    [self.tabBarIndexDelegate tabBarIndexSelected:1];
}


- (IBAction)tabNumberThree:(id)sender {

    [self.tabBarIndexDelegate tabBarIndexSelected:2];
}


- (IBAction)tabNumberFour:(id)sender {

    [self.tabBarIndexDelegate tabBarIndexSelected:3];
}

多数人,我错误的地方:(。

0 个答案:

没有答案