UINavigationControllerとUITableviewをサブクラス化していますが、適切なメソッドとリリース呼び出しをすべて実装しましたが、何らかの理由でビューのメモリリークが発生しています。サブクラスの代わりにネイティブクラスを使用すると、リークすることなくすべてが正常に機能します。
編集:
これが私のスーパークラスヘッダーです:
//
// MBAbstractViewController.h
// GabbaiHD
//
// Created by Moshe Berman on 11/24/10.
// Copyright 2010 MosheBerman.com. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface MBAbstractViewController : UIViewController {
IBOutlet UIImageView *backgroundImageView;
NSString *announcementText;
}
@property (nonatomic, retain) NSString *type;
@property (nonatomic, retain) NSDictionary *options;
@property (nonatomic, retain) NSString *announcementText;
-(void) setAnnouncementText:(NSString *)text;
@end
スーパークラスの実装:
//
// MBAbstractViewController.m
// GabbaiHD
//
// Created by Moshe Berman on 11/24/10.
// Copyright 2010 MosheBerman.com. All rights reserved.
//
#import "MBAbstractViewController.h"
@implementation MBAbstractViewController
@synthesize type, options, announcementText;
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
UIColor *clearColor = [[UIColor alloc] colorWithAlphaComponent:0.0];
[self.view setBackgroundColor: clearColor];
[clearColor release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight){
return YES;
}else{
return NO;
}
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[announcementText release];
[options release];
[type release];
[super dealloc];
}
@end
これが私のサブクラスヘッダーです:
//
// MBAnnouncementViewController.h
// GabbaiHD
//
// Created by Moshe Berman on 11/24/10.
// Copyright 2010 MosheBerman.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "MBAbstractViewController.h"
@interface MBAnnouncementViewController : MBAbstractViewController {
IBOutlet UILabel *announcement;
}
- (void) setAnnouncementText:(NSString *)text withSize:(CGFloat)size;
@end
およびサブクラスの実装:
//
// MBAnnouncementViewController.m
// GabbaiHD
//
// Created by Moshe Berman on 11/24/10.
// Copyright 2010 MosheBerman.com. All rights reserved.
//
#import "MBAnnouncementViewController.h"
#import "Constants.h"[
@implementation MBAnnouncementViewController
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
[announcement setText:announcementText];
UIImage *slideImage = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[[NSString stringWithFormat:@"%@_slide", kTheme]description] ofType:@"png"]];
[backgroundImageView setImage:slideImage];
[slideImage release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void) setAnnouncementText:(NSString *)text withSize:(CGFloat)size{
UIFont *font = [[UIFont alloc] fontWithSize:size];
[announcement setFont:font];
[font release];
[announcement setText:text];
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[announcementText release];
[super dealloc];
}
@end
サブクラスでメモリリークを引き起こしている可能性があるのは何ですか?私は何かが足りないのですか?(ここにはもっと関連性のあるコードがあります。)