将 BLOB 对象加载到 iPhone 中的数组中

发布于 2024-09-17 10:13:25 字数 114 浏览 3 评论 0原文

我需要用从 SQLite DB 检索的 BLOB 类型数据填充一个数组。目前我正在使用 NSData 来显示图像,但我想将图像放入数组中并将其显示在 UITableView 中

我该怎么做,请帮助我

I need to populate an array with BLOB type data retrived from SQLite DB.At present i am using NSData to display the image,but i want to put the image in an array and display it in the UITableView

How can i do this,please help me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

又怨 2024-09-24 10:13:25

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

    static NSString *CellIdentifier = @"Cell";

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    { 
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }
    else 
    {
        UIView* subview;
        while ((subview = [[[cell contentView] subviews] lastObject]) != nil)
            [subview removeFromSuperview];
    }

    UIView *vewmanulogo=[[UIView alloc]initWithFrame:CGRectMake(25,8,6,2)];

    sql=nil;
    stmt=nil;
    sql="select ManufacturerLogo from Manufacturer_tbl where ManufacturerID=?";
    sqlite3_prepare_v2(db, sql, -1, & stmt, NULL);
    NSLog(@"%@",manufacturerid);
    sqlite3_bind_int(stmt, 1,[ [manufacturerid objectAtIndex:indexPath.row]intValue]);    //manufacturer id is an array

    while(sqlite3_step(stmt)==SQLITE_ROW)
    {


        NSData *data = [[NSData alloc] initWithBytes:sqlite3_column_blob(stmt, 0) length:sqlite3_column_bytes(stmt, 0)];
            if(data == nil)
            {
                NSLog(@"No image found.");
            }
            else
            {

                [manufacturerlogo addObject:data];    //manufacturerlogo is an array

            }
    }
    UIImage *image = [UIImage imageWithData:[manufacturerlogo objectAtIndex:indexPath.row]]; //extracting individual images and assigning it to the UIImage
    UIImageView *manulogvw=[[UIImageView alloc]initWithImage:image];


    cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
    cell.selectionStyle=UITableViewCellSelectionStyleGray;
    [vewmanulogo addSubview:manulogvw];  //adding the image view to the view and making it as an content view to the cell.
    [cell.contentView addSubview:vewmanulogo];
    return cell;
}


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

    static NSString *CellIdentifier = @"Cell";

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    { 
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }
    else 
    {
        UIView* subview;
        while ((subview = [[[cell contentView] subviews] lastObject]) != nil)
            [subview removeFromSuperview];
    }

    UIView *vewmanulogo=[[UIView alloc]initWithFrame:CGRectMake(25,8,6,2)];

    sql=nil;
    stmt=nil;
    sql="select ManufacturerLogo from Manufacturer_tbl where ManufacturerID=?";
    sqlite3_prepare_v2(db, sql, -1, & stmt, NULL);
    NSLog(@"%@",manufacturerid);
    sqlite3_bind_int(stmt, 1,[ [manufacturerid objectAtIndex:indexPath.row]intValue]);    //manufacturer id is an array

    while(sqlite3_step(stmt)==SQLITE_ROW)
    {


        NSData *data = [[NSData alloc] initWithBytes:sqlite3_column_blob(stmt, 0) length:sqlite3_column_bytes(stmt, 0)];
            if(data == nil)
            {
                NSLog(@"No image found.");
            }
            else
            {

                [manufacturerlogo addObject:data];    //manufacturerlogo is an array

            }
    }
    UIImage *image = [UIImage imageWithData:[manufacturerlogo objectAtIndex:indexPath.row]]; //extracting individual images and assigning it to the UIImage
    UIImageView *manulogvw=[[UIImageView alloc]initWithImage:image];


    cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
    cell.selectionStyle=UITableViewCellSelectionStyleGray;
    [vewmanulogo addSubview:manulogvw];  //adding the image view to the view and making it as an content view to the cell.
    [cell.contentView addSubview:vewmanulogo];
    return cell;
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文