推送视图控制器上的自定义后退按钮单击事件

发布于 2024-08-27 18:28:21 字数 1508 浏览 6 评论 0原文

我已使用编程方式将视图控制器推送到视图中,并将右下角的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

熊抱啵儿 2024-09-03 18:28:21

您已经在此处使用了 -autoreleaseWebView

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 都不是免费的。

You have -autorelease'd WebView here:

WebView = [[[UIWebView alloc] initWithFrame:frame] autorelease];

but then you -release it again!

 [self.view addSubview: self.roundedButtonType ]; 
 [WebView release]; 

Try to remove one of the releases.


Also,

 self.roundedButtonType = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];

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 to self.roundedButtonType, because every call to self.roundedButtonType is not free.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文