Загрузка объектов BLOB в массив в iPhone - PullRequest
0 голосов
/ 05 сентября 2010

Мне нужно заполнить массив данными типа BLOB, полученными из базы данных SQLite. В настоящее время я использую NSData для отображения изображения, но я хочу поместить изображение в массив и отобразить его в UITableView

Как я могу это сделать, пожалуйста, помогите мне

1 Ответ

0 голосов
/ 07 сентября 2010

- (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;
}

...