私はアプリをiOS4と互換性があるように準備していますが、奇妙な理由で、segmentedControlの0インデックスを有効にすると、コードがopenDatabaseメソッドとcloseDatabaseメソッドを呼び出すという問題が発生しました。私はコード全体をデバッグしていて、segmentedControlが有効になるとすぐに、これら2つのメソッドが呼び出されることがわかりました。
ここにログの抜粋があります:
> 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'.
2つの後続のデータベースのオープンメソッドとクローズのメソッド呼び出しが表示されます。ただし、これらは私のコードによって明示的に呼び出されていませんが、「ゴースト」プロセスがコードのその部分を実行しています。
まったく同じコードがiOS5で問題なく実行され、シミュレーターでもデバイスでもまったく問題はありません。
何か考え、問題は何でしょうか?ありがとう。
- (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);
}
}