アプリケーションのすべての画面に表示されるカスタムバーを、機能するボタンとともに表示したいと思います。CustomViewControllerをinitメソッドのクラスに追加すると、アプリケーションを分析するときにメモリリークが発生する可能性があることを除いて、すべてが正しく機能します。
[customViewControllerリリース]を離すと、CustomViewControllerのボタンが機能しなくなります。メモリリークなしでこのソリューションを実装するための適切な方法は何ですか。
#import "CustomViewController.h"
@implementation CustomViewController
- (IBAction)doSomething:(id)sender
{
// Perform an action
}
@end
CustomViewControllerを作成するViewController:
- (id)initWithNibName:(NSString *)nibNameOrNil
bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
CustomViewController *customViewController = [[CustomViewController alloc] initWithNibName:@"CustomViewController" bundle:nil];
UIView *bar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
[bar addSubview:customViewController.view];
[self.view addSubview:bar];
[bar release];
}
}