1

试图拦截父 UIView 上的触摸事件,该父 UIView 封装了 UIScrollView 和另一个 UIView(叠加层),它们并排放置(意味着彼此重叠,在同一个容器视图中)。截至目前,我只是试图打印出在父 UIView 上确认 touchesBegan 事件的结果,但它抛出了 EXC_BAD_ACCESS,并出现以下错误:

    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.)

我认为所有相关代码都应该在下面。我也将整个项目上传到http://devmu.com/transfer/NoteMap.zip,如果这样更容易看到的话。

UIViewController 的加载视图:

- (void)loadView {
    [super loadView];

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

    self.view = container;
    //[self.view addSubview:container];

    [container release];
};
-the dealloc function releases the 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];
}

我有 ContainerView 的单独 nib 文件(从控制器加载),它是两个子视图,MapView 和 MapOverlayView(从 ContainerView 的 init 加载)。不知道这是否重要......但笔尖文件只引用了它们包含的视图。IE。ContainerView.xib 的 File Owner 是 UIViewController,它的唯一视图是 ContainerView。MapView.xib 和 MapOverlayView.xib 的 File Owner 是 ContainerView,其中包含 MapView 和 MapOverlayView 的两个引用(ContainerView/File Owner 的 IBOutlets)。

这可能是什么原因造成的?

谢谢你的帮助。

4

1 回答 1

-1

评论声明

[container release];

并使用 NSObject 的 dealloc() 释放容器对象分配的资源,以便

-(void) dealloc
{
  [self.containerView dealloc];
}
于 2011-09-09T08:20:53.397 回答