开发者

Loading BLOB objects into an array in iPhone

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



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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜