segmentedControl的setEnabled调用iOS 4中的其他方法

时间:2012-04-17 15:44:21

标签: iphone ios4 uisegmentedcontrol

我正在准备我的应用程序兼容iOS 4并且遇到了问题,出于某种奇怪的原因,启用segmentedControl的0索引会导致代码调用openDatabase方法和closeDatabase方法。我一直在调试整个代码,并且发现,只要启用了segmentedControl,就会调用这两个方法。

这里是日志的摘录:

> 2012-04-17 17:20:59.294 Abiliator[27897:11003] viewWillAppear - before database open
2012-04-17 17:20:59.296 Abiliator[27897:11003] OpenDatabase
2012-04-17 17:20:59.297 Abiliator[27897:11003] viewWillAppear - loadAppSettings
2012-04-17 17:20:59.311 Abiliator[27897:11003] viewWillAppear - getCurrentLearningSubject
2012-04-17 17:20:59.340 Abiliator[27897:11003] viewWillAppear - switchLearningBoxControl
2012-04-17 17:20:59.341 Abiliator[27897:11003] Inside switchLearningBoxControl
**2012-04-17 17:20:59.394 Abiliator[27897:11003] OpenDatabase
2012-04-17 17:21:00.566 Abiliator[27897:11003] CloseDatabase**
2012-04-17 17:21:00.567 Abiliator[27897:11003] Method abiliatorViewController - Function switchLearningBoxControl: Error preparing the statement 'library routine called out of sequence'.
2012-04-17 17:21:00.568 Abiliator[27897:11003] Method abiliatorViewController - Function switchLearningBoxControl: Error preparing the statement 'library routine called out of sequence'.
2012-04-17 17:21:00.569 Abiliator[27897:11003] Method abiliatorViewController - Function switchLearningBoxControl: Error preparing the statement 'library routine called out of sequence'.
2012-04-17 17:21:00.570 Abiliator[27897:11003] Method abiliatorViewController - Function switchLearningBoxControl: Error preparing the statement 'library routine called out of sequence'.
2012-04-17 17:21:00.570 Abiliator[27897:11003] Finished switchLearningBoxControl
2012-04-17 17:21:00.571 Abiliator[27897:11003] viewWillAppear - getQuestionFromDB
2012-04-17 17:21:00.572 Abiliator[27897:11003] CloseDatabase
2012-04-17 17:21:00.572 Abiliator[27897:11003] Failed to close the database with message 'library routine called out of sequence'.

您会看到两个后续的打开和关闭数据库方法调用。但是我的代码没有明确地调用它们,但是一些“ghost”进程正在执行代码的那部分。

完全相同的代码在iOS 5上运行很好,完全没有问题,无论是在模拟器中还是在设备上。

任何想法,问题可能是什么?感谢。

- (void) switchLearningBoxControl:(NSString *) mySubjectID {
const char *sql = "select count (*) from ABILIATOR_CARD where learningbox = ? and subject_id = ?";
for (NSInteger mySegment=0;mySegment < 5;mySegment++) {
    sqlite3_stmt *selectstmt;

    if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
        sqlite3_bind_int(selectstmt, 1, mySegment+1);
        sqlite3_bind_text(selectstmt, 2, [mySubjectID UTF8String], -1, SQLITE_TRANSIENT);
        if (sqlite3_step(selectstmt) == SQLITE_ROW) {
            int count = sqlite3_column_int(selectstmt, 0);
            if (count < 1) {
                [self.learningBoxControl setEnabled:NO forSegmentAtIndex:mySegment];
            }
            else {
                [self.learningBoxControl setEnabled:YES forSegmentAtIndex:mySegment];
            }
        }
        else {
            [self.learningBoxControl setEnabled:NO forSegmentAtIndex:mySegment];
        }

    }
    else {
        NSLog(@"Method abiliatorViewController - Function switchLearningBoxControl: Error preparing the statement '%s'.", sqlite3_errmsg(database));
    }
    sqlite3_finalize(selectstmt);   
}
}

1 个答案:

答案 0 :(得分:0)

在iOS 4中,setEnabled调用IBAction,iOS 5则没有。我在IBAction中有另一个开放,当然混淆了应用程序:-)我没有意识到这种变化,因为我已经阅读了文档并且在4和5之间没有看到任何这样的变化。