无法为按钮执行内部动作修饰

时间:2015-02-15 20:28:00

标签: ios objective-c iphone uiview uiviewcontroller

我的界面构建器中有一个按钮(顺便使用nib),我控制从按钮拖动到视图控制器.h文件并将其命名为“cancelReminder”(并将其设置为动作):

@interface HomeViewController : UIViewController 

@property (strong, nonatomic) IBOutlet UILabel *homeLabel;

@property (strong, nonatomic) IBOutlet UIScrollView *myScrollView;

- (IBAction)cancelReminder:(id)sender;

@end

这在.m文件中创建了一个方法,我只是在那里用“取消”来测试它。

在界面构建器中,我控制从按钮拖动到文件所有者,以确保它连接到方法“cancelReminder”。

这应该正确吗?它没有。

值得一提的是:取消按钮是视图的子项,此视图是主视图的子视图。

看起来像这样:

enter image description here

我知道我不应该这样做,但只是为了测试行为,如果我控制从取消按钮拖动到文件所有者并选择视图,当我运行应用程序时,我看到黑屏,我可以看到按钮及其工作...通过工作我的意思是方法正在响应:

enter image description here

我把它拿回来了,我试过了,所以也许有人会从这种行为中理解发生了什么。

请帮我解决这个问题:///之前发生过:(

比一堆!!

my viewDiLoad:

- (void)viewDidLoad {

    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.slidingView.hidden = YES;
    // black BG to make the background darker when the reminder view is sliding in
    self.reminderBG.hidden = YES;
    self.navigationController.navigationBarHidden = YES;
    self.homeLabel.font = [UIFont fontWithName:@"Candara-Bold" size:40];
    self.homeLabel.text = stackTableViewController.currentTarget;
    self.homeLabel.lineBreakMode = NSLineBreakByWordWrapping;
    self.homeLabel.numberOfLines = 0;
    self.myScrollView.delegate = self;

    //setting up the button bounds
    self.buttonBounds = self.createButton.bounds;

    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapResponder)];

    tapRecognizer.numberOfTapsRequired =1;
    tapRecognizer.numberOfTouchesRequired = 1;

    [self.homeLabel addGestureRecognizer:tapRecognizer];
}

和我的操作表方法,用于滑动提醒视图:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (buttonIndex == 0) {

    } else if (buttonIndex == 1) {

        self.reminderBG.hidden = NO;
        self.slidingView.hidden = NO;
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        self.slidingView.frame = CGRectMake(0,0,320,20);
        self.view.frame = CGRectMake(0,0,320,460);
        [UIView commitAnimations];
    }
}

enter image description here

1 个答案:

答案 0 :(得分:0)

问题可能是由手势识别器引起的。尝试在创建tapRecognizer后添加委托:

tapRecognizer.delegate = self;

并使用委托方法:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if ([touch.view isKindOfClass:[UIButton class]]){
        return NO;
    }
    return YES;
}