显示/隐藏按钮时应用程序崩溃

时间:2012-10-13 21:44:40

标签: ios crash uigesturerecognizer show-hide

我实现了一个基本类型的图片库(非常类似于iPhone上的照片应用程序),我有一个按钮,当按下时会返回什么。嗯,它可以工作但只在少数情况下。图库基本上是一个UIPageControl,它有一层UIScrollView,顶部是UIImageView。它可以在页面之间传递(因此,在图像之间)。但该按钮仅在第一页上显示和访问。我使用手势(在这种情况下是点按)来显示按钮。如果我没有移出第一页,这个按钮才有效。如果我转到第二页然后回到第一页,当我点击屏幕显示应用程序崩溃的按钮时,这有点复杂的解释那。这是我用来显示按钮的代码:

//.h

@interface ImatgesNouViewController : UIViewController <UIScrollViewDelegate, UIGestureRecognizerDelegate> {
UIScrollView *bgScorllView;        
UIView *bgView;                           
UIImageView *picImageView;      
UIScrollView *picScrollView;   
UIImageView *preImageView;   
UIImageView *nextImageView;
}

//.m
-(void)viewDidLoad{
[super viewDidLoad];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap:)];
tapGesture.numberOfTapsRequired = 1;
[tapGesture setDelegate:self];
[self.view addGestureRecognizer:tapGesture];
}

然后为图片库加载不同的内容。

-(void) didTap:(id) sender{


if (boto.hidden == YES){

    [picImageView addSubview:boto];



    boto.hidden = NO;
    NSLog(@"apareix");
} else {

    [picImageView addSubview:boto];


    boto.hidden = YES;
    NSLog(@"desapareix");
}

}

我将代码更新为void操作,现在我有更多问题的详细信息。使用旧代码,该按钮仅显示在图库的第一页上。现在它可以显示在图库的每个页面上。现在我知道什么时候崩溃了:如果我点击屏幕显示按钮然后再次点击以隐藏它,它会按照我想要的次数工作。但是,如果在这之后我想去其他页面,那么它会崩溃。我希望通过这些信息可以更快地解决问题。

崩溃日志:由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'(null)' * 第一次抛出调用堆栈: (0x19b6012 0x1448e7e 0x19b5e78 0xedef35 0xff93a2 0x3d5c4f 0x3e7748 0x3e7c9d 0x3ee5ec 0x3f20e7 0x65a89a 0x6599db 0x65b11f 0x65dd6d 0x65dcec 0x655a68 0x3c2fc2 0x3c34a3 0x3a13aa 0x392cf8 0x1800df9 0x1800ad0 0x192bbf5 0x192b962 0x195cbb6 0x195bf44 0x195be1b 0x17ff7e3 0x17ff668 0x39065c 0x1ee8c 0x2395为0x1) libc ++ abi.dylib:terminate调用抛出异常 (lldb)

(抱歉这么晚发布崩溃日志)

我不知道到底发生了什么以及这次崩溃的原因。可能是手势识别在图像之间滑动导致此崩溃(与一次轻击的手势相结合)。感谢先进的帮助!

2 个答案:

答案 0 :(得分:0)

试试这个......

更改 动作:@selector(didTap) 至 动作:@selector(didTap:)

更改 - (void)didTap { 至 - (void)didTap:(id)sender {

答案 1 :(得分:0)

我找到了问题的答案。在思考了一下之后,我看到按钮前面的顶部有几个物体。因此,我必须将按钮置于顶部,但通过向视图添加子视图(与其他对象一样)更容易。有了这个,按钮始终保持在顶部,但随后,使用轻击手势和void命令,我将其隐藏从Yes更改为NO。这是代码:

- (void)viewDidLoad
{
[super viewDidLoad];    
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap:)];
tapGesture.numberOfTapsRequired = 1;
[tapGesture setDelegate:self];
[self.view addGestureRecognizer:tapGesture];
[self.view addSubview:boto];
[boto setHidden:YES];     }

-(void) didTap:(id) sender
{
if (boto.hidden == YES){
          [self.view addSubview:boto];
    boto.hidden = NO;
    NSLog(@"apareix");

} else {
    [boto removeFromSuperview];
    boto.hidden = YES;
    NSLog(@"desapareix");
    [self.view addSubview:boto];
}
}

感谢每一个人帮助我,在你所有人的帮助下,我能够开始工作,这显然很简单。