objective-c - 转到另一个函数中的标签

标签 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..
}

看来我做不到,我该怎么做呢?提前谢谢。

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

-(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;
}

最佳答案

试试这个:

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

-(void)function2{

//some code..
}

而且,只有在非常非常特殊的情况下才允许使用“gotos”,你现在应该忘掉它们!它再次适用于任何开发原则。

关于objective-c - 转到另一个函数中的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9685333/

相关文章:

ios - UICollectionView 标题标题消失后

ios - 在 Xcode 中保存 NSMutableArray 的其他方法

ios - 在导航回 UINavigationController 堆栈中的前一个 Controller 之前向用户提示 UIAlertView

iOS : ModalView with background transparent?

ios - Objective-C:UILocalNotification

ios - UITableViewCell 在滚动后被复制

ios - 是否可以在iOS中创建和使用FIFO文件? (ObjC)

objective-c - 像 iPad 上的 iMessage 应用程序一样拆分键盘

ios - 为 UITableViewCell 附件的背景设置自定义颜色

iphone - iOS,选择哪个数据库?