开发者

EXC_BAD_ACCESS: When trying to handle touches event in parent UIVIew

Trying to intercept the touch events on a parent UIView, which is encapsulating both a UIScrollView, and another UIView (an overlay), which sit side by side (meaning on top of each other, in the same container view). As of now I'm just trying to print out the result of the acknowledgement of the touchesBegan event on the parent UIView, but it's throwing EXC_BAD_ACCESS, with this error:

    Program received signal:  “EXC_BAD_ACCESS”.
    warning: Unable to restore previously selected frame.
    Data Formatters temporarily unavailable, will re-try after a 'continue'. (Not safe    
    to call dlopen at this time.)

I think all of the relevant code should be below. I uploaded the whole project to http://devmu.com/transfer/NoteMap.zip as well, if that's easier to see.

loadView of the UIViewController:

- (void)loadView {
    [super loadView];

    [[NSBundle mainBundle] loadNibNamed:@"ContainerView" owner:self options:nil];       
    ContainerView *container = self.containerView = [[ContainerView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];

    self.vie开发者_运维百科w = container;
    //[self.view addSubview:container];

    [container release];
};
-the dealloc function releases the containerView

ContainerView:

@implementation ContainerView

@synthesize overlayView=_overlayerView, scrollView=_scrollView;

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        //setup scrollview
        [[NSBundle mainBundle] loadNibNamed:@"GridScrollView" owner:self options:nil];
        self.scrollView = [[GridScrollView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
        [self addSubview:self.scrollView];

        //setup overlayview
        NSArray *nibOverlayContents = [[NSBundle mainBundle] loadNibNamed:@"MapOverlayView" owner:self options:nil];
        self.overlayView = [nibOverlayContents objectAtIndex:0];
        [self addSubview:self.overlayView];     
    }
    return self;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    NSLog(@"ContainerView touchesBegan");
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"ContainerView touchesEnded");
}

- (void)dealloc {
    [self.overlayView release];
    [self.scrollView release];
    [super dealloc];
}

I have separate nib files for the ContainerView (loaded from the controller), and it's two subviews, MapView and the MapOverlayView (loaded from ContainerView's init). Not sure if it should matter... but the nib files only have a reference to their containing views. ie. ContainerView.xib's File Owner is the UIViewController, and it's only view is ContainerView. MapView.xib and MapOverlayView.xib's File Owner is ContainerView, and it contains two references to MapView and MapOverlayView (IBOutlets of the ContainerView/File Owner).

What could be causing this?

Thanks for any help.


comment statement

[container release];

and release the resource allocated by container object using dealloc() of NSObject so as

-(void) dealloc
{
  [self.containerView dealloc];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜