推送视图控制器上的自定义后退按钮单击事件
我已使用编程方式将视图控制器推送到视图中,并将右下角的 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 消息。
如何解决这个问题?
谢谢,
I have pushed view controller and load WebView and Custom rectangular rounded button on right down left corner into view using programmatic way.
-(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];
}
This is action that I have added as back button of navigation.
-(void)back:(id)sender{
[self.navigationController popViewControllerAnimated:YES];
}
-(void)viewDidUnload{
self.WebView = nil;
self.roundedButtonType = nil;
}
-(void)dealloc{
[roundedButtonType release];
[super dealloc];
}
Here, When Back button click then it is showing previous view but application got stuck in that view and GDB shows Program received signal :EXC_BAD_ACCESS message.
how resolve this issue?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经在此处使用了
-autorelease
的WebView
:但随后您再次
-release
了!尝试删除其中一个版本。
此外,
除非将
roundedButtonType
声明为@property(assign,...)
,否则您不需要发送-retain
消息。最好在分配给self.roundedButtonType
之前设置框架、标题等,因为每次调用self.roundedButtonType
都不是免费的。You have
-autorelease
'dWebView
here:but then you
-release
it again!Try to remove one of the releases.
Also,
unless
roundedButtonType
is declared as@property(assign,...)
, you don't need to send the-retain
message. And it's better to setup the frame, title, etc. before assigning toself.roundedButtonType
, because every call toself.roundedButtonType
is not free.