我正在准备我的应用程序与 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'.
您会看到两个后续的打开和关闭数据库方法调用。然而,我的代码没有明确调用这些,但是一些“幽灵”进程正在执行那部分代码。
相同的代码在 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);
}
}