0

我有一个包含 5 条记录的数据库,我需要使用计时器在屏幕上一一显示记录。时间间隔应为 30 秒。

- (NSMutableArray*) fnGetName 
{

DBCon *oDBCon = [[DBCon alloc] init];
[oDBCon fnInitializeDB];
NSMutableArray *arrDict = [[NSMutableArray alloc] init];
NSString *sQryName = [NSString stringWithFormat:@"SELECT * FROM tbl_names"];
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(oDBCon.database, [sQryName UTF8String], -1, &selectstmt, NULL) == SQLITE_OK) 
{
        while(sqlite3_step(selectstmt) == SQLITE_ROW) {
        oBlossom = [[Blossom alloc]initWithPrimaryKey:primaryKey database:oDBCon.database];
        oBlossom.psName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt,1)];
        NSLog(@"oBlossom.psName %@", oBlossom.psName);
        oBlossom.psKeyword = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt,2)];
        NSLog(@"oBlossom.psKeyword %@", oBlossom.psKeyword);
        [arrDict addObject:oBlossom];

}
4

1 回答 1

0

返回arrDict并使用 Timer 更新 UI

注意:当您完成操作时使计时器无效。否则它不会停止并会导致崩溃。

-(void)disaplydisplayRecordsWithTimeInterval{

    NSMutableArray *myCollection = [self fnGetName];

    NSTimer timerWithTimeInterval:30.0 target:self selector:@selector(displayRecords:) userInfo:arrDict repeats:YES];

}

- (void)displayRecords:(NSTimer*)theTimer {

    NSMutableArray *myArrayCollection = (NSMutableArray *)theTimer.userInfo;
    //your code here to displayRecords using myarrDict
}

- (NSMutableArray*) fnGetName {

    DBCon *oDBCon = [[DBCon alloc] init];
    [oDBCon fnInitializeDB];
    NSMutableArray *arrDict = [[NSMutableArray alloc] init];
    NSString *sQryName = [NSString stringWithFormat:@"SELECT * FROM tbl_names"];
    sqlite3_stmt *selectstmt;
    if(sqlite3_prepare_v2(oDBCon.database, [sQryName UTF8String], -1, &selectstmt, NULL) == SQLITE_OK) 
    {
        while(sqlite3_step(selectstmt) == SQLITE_ROW) {
            oBlossom = [[Blossom alloc]initWithPrimaryKey:primaryKey database:oDBCon.database];
            oBlossom.psName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt,1)];
            NSLog(@"oBlossom.psName %@", oBlossom.psName);
            oBlossom.psKeyword = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt,2)];
            NSLog(@"oBlossom.psKeyword %@", oBlossom.psKeyword);
            [arrDict addObject:oBlossom];

        }

        //finilize database here
    }

    //close database here

    return arrDict;
}
于 2012-08-03T11:22:34.463 回答