我已经推动了视图控制器,并使用编程方式将右下角的WebView和自定义矩形圆形按钮加载到视图中。
-(void)loadView {
CGRect frame = CGRectMake(0.0, 0.0, 480, 320);
WebView = [[[UIWebView alloc] initWithFrame:frame] autorelease];
WebView.backgroundColor = [UIColor whiteColor];
WebView.scalesPageToFit = YES;
WebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin);
WebView.autoresizesSubviews = YES;
WebView.exclusiveTouch = YES;
WebView.clearsContextBeforeDrawing = YES;
self.roundedButtonType = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
self.roundedButtonType.frame = CGRectMake(416.0, 270.0, 44, 19);
[self.roundedButtonType setTitle:@"Back" forState:UIControlStateNormal];
self.roundedButtonType.backgroundColor = [UIColor grayColor];
[self.roundedButtonType addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
self.view = WebView;
[self.view addSubview: self.roundedButtonType ];
[WebView release];
}
这是我作为导航后退按钮添加的操作。
-(void)back:(id)sender{
[self.navigationController popViewControllerAnimated:YES];
}
-(void)viewDidUnload{
self.WebView = nil;
self.roundedButtonType = nil;
}
-(void)dealloc{
[roundedButtonType release];
[super dealloc];
}
此处,单击“返回”按钮后,它显示上一个视图,但应用程序卡在该视图中,GDB显示程序接收信号:EXC_BAD_ACCESS消息。
如何解决这个问题?
谢谢,
答案 0 :(得分:0)
您在这里-autorelease
'd WebView
:
WebView = [[[UIWebView alloc] initWithFrame:frame] autorelease];
但是你再次-release
了!
[self.view addSubview: self.roundedButtonType ];
[WebView release];
尝试删除其中一个版本。
此外,
self.roundedButtonType = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
除非roundedButtonType
被声明为@property(assign,...)
,否则您无需发送-retain
消息。最好在分配到self.roundedButtonType
之前设置框架,标题等,因为对self.roundedButtonType
的每次调用都不是免费的。