iphone - 如何将字符串值显示到 UITableView?

标签 iphone objective-c ios

{
NSString *docsDir;
NSArray *dirPaths;

// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

docsDir = [dirPaths objectAtIndex:0];
//array=[[NSMutableArray alloc]init];
//array1=[[NSMutableArray alloc]init];

// Build the path to the database file
databasePath =  [docsDir stringByAppendingPathComponent: @"first.database"];
NSLog(@"%@",databasePath);
NSFileManager *fn=[NSFileManager defaultManager];
NSError *error;
BOOL success=[fn fileExistsAtPath:databasePath];

if(!success) {

    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"first.database"];
    success = [fn copyItemAtPath:defaultDBPath toPath:databasePath error:&error];
}


const char *dbpath = [databasePath UTF8String];
sqlite3_stmt    *statement;

if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
{
    NSString *querySQL = [NSString stringWithFormat: @"SELECT firstname FROM second"];

    const char *query_stmt = [querySQL UTF8String];

    if (sqlite3_prepare_v2(contactDB, query_stmt, -1, &statement, NULL) == SQLITE_OK)
    {
        if (sqlite3_step(statement) == SQLITE_ROW)
        {

            arrival = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement,0)];


       NSLog(@"Result %@",arrival);


        sqlite3_finalize(statement);
    }
    sqlite3_close(contactDB);
     [self.tableView reloadData];
}
}

在此示例中,我想向 UITableView 显示“到达”值...任何人都可以帮助我

最佳答案

首先 - 对 sqlite 数据库使用 FMDB 包装器。它让生活变得如此轻松! (检查他们的 GitHub herethis tutorial ) 其次 - 如果你想将 SELECT 的结果分配给单元格,只需使用:

cell.textLabel.text = your_result;

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

关于iphone - 如何将字符串值显示到 UITableView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12246958/

相关文章:

iphone - 用户与 uiview 和动画完成 block 的交互

iphone - UIView动画异常

ios - 点击 UIButton 后显示 UITableView

ios - iPhone 上使用 Youtube Iframe API 的全屏状态

ios - 为什么在安装应用程序时启动 Paper-Onboarding 时导航 Controller 消失?

ios - 使用 RESTKit 映射 iTunes 搜索 API 结果

iphone - 是否需要缓存CoreData返回的数据?

ios - XMPP 房间邀请好友 IOS

ios - 如何自动布局并将应用程序部署到应用程序商店

ios - 停止背景音乐