0

尝试使用 iPhone SDK 的 OpenFlow API。我需要 openflow 从(图像)链接加载图片。

这就是它始终与本地图像一起工作的方式:

    loadImagesOperationQueue = [[NSOperationQueue alloc] init];


    NSString *imageName;
    for (int i=0; i < 10; i++) {
        imageName = [[NSString alloc] initWithFormat:@"cover_%d.jpg", i];
        [(AFOpenFlowView *)self.view setImage:[UIImage imageNamed:imageName] forIndex:i];
        [imageName release];
        NSLog(@"%d is the index",i);

    }
    [(AFOpenFlowView *)self.view setNumberOfImages:10];

我试过这个:

    - (void)openFlowView:(AFOpenFlowView *)openFlowView requestImageForIndex:(int)index {

    NSString *photoUrl = [[oldEntries objectAtIndex: 0] objectForKey: @"still"];
    NSURL *photomake = [NSURL URLWithString:photoUrl];
    NSLog(@"theConnection: %@",photoUrl);
    NSLog(@"theConnection: %@",photomake);

    AFGetImageOperation *getImageOperation = [AFGetImageOperation alloc];
    // We're getting our images from the Flickr API.
    getImageOperation.imageURL = photomake;

    [loadImagesOperationQueue addOperation:getImageOperation];

    [(AFOpenFlowView *)self.view setNumberOfImages:1];
    [getImageOperation release];
}

但它只是行不通。谁能帮我?

4

2 回答 2

0

它更容易使用:

NSURL *imageUrl = [[NSURL alloc] initWithString:[@"path/to/the/file.jpg"];
NSData *imageData = [NSData dataWithContentsOfURL:imageUrl];
UIImage *image = [UIImage imageWithData:imageData];

将所有图像放在一个数组中,然后调用第一个函数

for (int i=0; i < 10; i++) {
    imageName = [[NSString alloc] initWithFormat:@"cover_%d.jpg", i];
    [(AFOpenFlowView *)self.view setImage:**image** forIndex:i];
    [imageName release];
    NSLog(@"%d is the index",i);

}
[(AFOpenFlowView *)self.view setNumberOfImages:10];
于 2011-07-29T18:41:38.680 回答
0

在不知道什么“行不通”的情况下很难说,请澄清并提供您正在创建的实际 URL。

唯一看起来可疑的行是这一行:

AFGetImageOperation *getImageOperation = [AFGetImageOperation alloc];

应该:

AFGetImageOperation *getImageOperation = [[AFGetImageOperation alloc] init];
于 2011-05-17T18:46:36.423 回答