我想顯示一個自定義欄,出現在我的應用程序的每個屏幕上,並帶有可用的按鈕。我將initView方法中的CustomViewController添加到我的類中,除非在分析我的應用程序時發生潛在的內存泄漏,否則一切正常。CustomViewController在整個應用程序
當我釋放[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];
}
}
按鈕在界面生成器中連接,因此沒有 – Vikings 2012-04-24 18:31:06