开发者

Custom back button click event on pushed view controller

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{
 [sel开发者_Python百科f.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,


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜