尝试截取父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的loadView:
- (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
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加载)。不确定它是否重要......但是nib文件只引用了它们包含的视图。即。 ContainerView.xib的文件所有者是UIViewController,它的唯一视图是ContainerView。 MapView.xib和MapOverlayView.xib的文件所有者是ContainerView,它包含对MapView和MapOverlayView的两个引用(ContainerView / File Owner的IBOutlets)。
导致这种情况的原因是什么?
感谢您的帮助。
答案 0 :(得分:-1)
评论声明
[container release];
并使用NSObject的dealloc()释放容器对象分配的资源,以便
-(void) dealloc
{
[self.containerView dealloc];
}