转到另一个功能的标签

Luc*_*uca 0 objective-c ios

我需要这样做:

-(void)function1{
goto start;
}

-(void)function2{
//some code
start://i need to get in here exactly, [self function2] oblige me to execute the function2 from the beginning
//some code..
}
Run Code Online (Sandbox Code Playgroud)

似乎我不能,我能做什么呢?提前.

编辑:这是我的实际代码:

-(void)viewWillAppear:(BOOL)animated{
if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
    {
        NSString *querySQL = [NSString stringWithFormat: 
                              @"Select quiz,question,p1,p2,p3,num_correct from question where quiz=(select id from quiz where nom = \'%@\' and niveau= \'%i\' and theme=(select id from theme where nom=\'%@\'))",nomPartieQuiz,quiIslam.theGameLevel,quiIslam.themeChoisie];

        const char *query_stmt = [querySQL UTF8String];

        if (sqlite3_prepare_v2(contactDB, 
                               query_stmt, -1, &statement, NULL) == SQLITE_OK)
        {
        start://étiquette
            while (sqlite3_step(statement) == SQLITE_ROW && !passToNextQuestion)
            {



                NSString *addressField = [[NSString alloc] 
                                          initWithUTF8String:
                                          (const char *) sqlite3_column_text(
                                                                             statement, 1)];

                NSLog(@"%@",addressField); 
                txtView.text=addressField;

                passToNextQuestion=NO;                                

            }

            sqlite3_finalize(statement);
        }
        sqlite3_close(contactDB);
    }

}


-(IBAction)clickOnTheButton:(id)sender{

    btn1.hidden=YES;
    goto start;
}
Run Code Online (Sandbox Code Playgroud)

Ant*_* MG 6

试试这个:

-(void)function1{
 [self function2];
}

-(void)function2{

//some code..
}
Run Code Online (Sandbox Code Playgroud)

并且,使用"gotos"只允许在非常非常特殊的情况下,你现在应该忘记它们!它再次成为任何发展原则.

  • 如果您需要"转到"代码中的任何特定行,那么您已经非常糟糕地搞砸了.正如这个答案所说,你应该将你需要在goto中执行的任何代码移动到一个方法中,然后调用它而不是跳出你当前的方法.如果你不想在方法之后再执行任何逻辑,只需调用return; 并退出该方法. (2认同)