RemoveFromSuperview crashes my application

I am sure this is a stupid mistake, but I have been trying for the last hour to remove the preview from my supervisor without any success.

In my first view, I have

UIViewController *helpView = [[[UIViewController alloc] initWithNibName:@"HelpView" bundle:nil] autorelease];
[self.view addSubview:helpView.view];

And then inside helpView, I have a button that is associated with an IBAction called "closeHelp", which simply does the following:

- (IBAction) closeHelp{
    [self.view removeFromSuperview];
}

But this leads to the fact that my application crashes with EXC_BAS_ACCESS for some strange reason, even those that are inside the HelpView, that is, self.view should point to the correct one for viewing.

Thank your help

Thank.
Shay.

+5
source share
5 answers

, self.view / . helpView .

- (IBAction) closeHelp{
    [helpView removeFromSuperview];
}

, "helpView" . .

, .

#define HELP_VIEW_TAG 101 // Give tag of your choice

HelpView *helpView = [[HelpView alloc] initWithNibName:@"HelpView" bundle:nil];
helpView.view.tag = HELP_VIEW_TAG;
[self.view addSubview:helpView.view];
[helpView release];

- (IBAction) closeHelp{
    UIView *helpView = [self.view viewWithTag:HELP_VIEW_TAG];
    [helpView removeFromSuperview];
}
+5

Self.view subview, , uiviewcontroller. , subview, , .

, viewcontroller ?

[self presentModalViewController:helpView animated:NO/YES];

helpView. modalTransitionStyle = //One of the constants below

UIModalTransitionStyleCoverVertical
UIModalTransitionStyleFlipHorizontal
UIModalTransitionStyleCrossDissolve
UIModalTransitionStylePartialCurl

self.modalTransitionStyle = // One of the constants viewcontroller, , , .

+2

helpView UIViewController.
, #import "HelpView.h" ( - HelpView.h) .h , .

:

HelpView *helpView = [[HelpView alloc] initWithNibName:@"HelpView" bundle:nil];
[self.view addSubview:helpView.view];

.

+1

, XIB , , , , , .:)

0
Declare the help view on calss level.

in.h file 

@class HelpView;
..
@interface
{
HelpView *helpView;
}
@property(nonatomic,retain)HelpView*  helpView;


In.m file 
#import "HelpView"
@synthensize helpView;



now add this Code where you want 

helpView = [[HelpView alloc] initWithNibName:@"HelpView" bundle:nil];
helpView.view.tag = HELP_VIEW_TAG;
[self.view addSubview:helpView.view];


- (IBAction) closeHelp{
    //UIView *helpView = [self.view viewWithTag:HELP_VIEW_TAG];
    [helpView removeFromSuperview];
}

- () dealloc { [ helpView]; }

-1

All Articles