ios - 从webservice和BDD mysql下载图像

时间:2015-01-31 20:41:44

标签: ios mysql objective-c image

我有一个获取数据的网络服务。在这个数据中我有图像:在mysql基础中它声明为" BLOB"。

我的问题是当我想在imageview中给它时它不会出现....留空。...

我收到了json格式的回复。 BLOB编码为base64 ...

感谢您的帮助。

编辑: 我这样做:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    // Create an array to store the locations
    NSMutableArray *_articles = [[NSMutableArray alloc] init];

    // Parse the JSON that came in
    NSError *error;
    NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:_downloadedData options:NSJSONReadingAllowFragments error:&error];

    // Loop through Json objects, create question objects and add them to our questions array
    for (int i = 0; i < jsonArray.count; i++)
        {
        NSDictionary *jsonElement = jsonArray[i];

        // Create a new location object and set its props to JsonElement properties
        Article *newArticle = [[Article alloc] init];
        newArticle.IMAGE = jsonElement[@"IMAGE"];
        newArticle.DESIGNATION = jsonElement[@"DESIGNATION"];
        newArticle.CODE_ARTICLE = jsonElement[@"CODE_ARTICLE"];

        [_articles addObject:newArticle];
        }

    // Ready to notify delegate that data is ready and pass back items
    if (self.delegate)
        {
        [self.delegate itemsDownloaded:_articles];
        }

    if(error) {
        [HUD showTimedErrorWithTitle:@"Erreur" text:@"Récupération des articles impossible ..." withTimeout:5];
    }
    else [HUD hideUIBlockingIndicator];
}

... .. 检索数据。

这将出现在视图中:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Retrieve cell
    NSString *cellIdentifier = @"ArticleCell";
    UITableViewCell *myCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    Article *item = _feedItems[indexPath.row];

    // Get references to labels of cell
    myCell.textLabel.text = item.DESIGNATION;
    myCell.detailTextLabel.text = item.CODE_ARTICLE;
    myCell.detailTextLabel.numberOfLines = 2;
    //cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;

    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
    imgView.image = item.IMAGE;

    // Begin a new image that will be the new image with the rounded corners
    // (here with the size of an UIImageView)
    UIGraphicsBeginImageContextWithOptions(imgView.bounds.size, NO, 1.0);

    // Add a clip before drawing anything, in the shape of an rounded rect
    [[UIBezierPath bezierPathWithRoundedRect:imgView.bounds
                                cornerRadius:20.0] addClip];
    // Draw your image
    [imgView.image drawInRect:imgView.bounds];

    // Get the image, here setting the UIImageView image
    imgView.image = UIGraphicsGetImageFromCurrentImageContext();

    // Lets forget about that we were drawing
    UIGraphicsEndImageContext();

    myCell.imageView.image = imgView.image;

    return myCell;
}

由于

0 个答案:

没有答案