Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在不触摸UIButton的情况下调用UIButton选择器_Objective C_Ios_Uibutton_Ibaction - Fatal编程技术网

Objective c 在不触摸UIButton的情况下调用UIButton选择器

Objective c 在不触摸UIButton的情况下调用UIButton选择器,objective-c,ios,uibutton,ibaction,Objective C,Ios,Uibutton,Ibaction,我有一个棘手的问题,希望你能理解: 我有一个带选择器的UIButton: - (void)ButtonPressed:(id)sender{ UIButton *button = (UIButton*) sender; int tag = -1; if (iniciat == 0){ if(button.tag == START) { tag = 0; iniciat = 1; [s

我有一个棘手的问题,希望你能理解:

我有一个带选择器的UIButton:

- (void)ButtonPressed:(id)sender{
    UIButton *button = (UIButton*) sender;
    int tag = -1;

    if (iniciat == 0){
        if(button.tag == START) {
            tag = 0;
            iniciat = 1;
            [self TimeControl];
        }
    }else{
        switch (button.tag) {
            case START: //Start
                break;
            case LEFT://LEFT  
                //Do sth
                break;
            case RIGHT://RIGHT
                //Do sth
                break;
            default:
                break;
        }

    [super viewDidLoad];

    }
}
但我想在完成某些操作时使用/调用此选择器,除了UIButton的触摸操作。 我所做的是:

-(void) checkNXT{
    if (iniciat) {

        aux1 = [NSString stringWithFormat:@"%@", newString];
        bool pressed=[aux1 isEqualToString:@"30a0a00\n"];
        bool pressed2=[aux1 isEqualToString:@"30d0d00\n"];

        if(pressed == TRUE){ //Esquerre
            [self ButtonPressed:buttonLeft];

        }else if(pressed2 == TRUE){
            [self ButtonPressed:buttonRight];

        }

        aux3 = [NSString stringWithFormat:@"%d",count];
    }
    [super viewDidLoad];
}
但不知何故,它不能正常工作-->它不能调用ButtonPressed函数


谢谢大家!

那两个
viewdiload
是如何在那里结束的?删除它们。您可以将要执行的代码放在不同的方法上,然后从所需的位置以及按钮操作调用该方法。您应该能够从任意位置调用ButtonPressed方法,无论该方法是否被指定为按钮的选择器。您确定您的代码到达了调用它的行吗?尝试将断点设置为
[self ButtonPressed:buttonLeft]和<代码>[自按按钮:按钮右]。我想这就是问题所在。如果到达这些行,请在按下的
按钮的第一行设置一个断点,然后查看是否达到该断点