0

我有一个示例代码可以从下面的代码中在 gridview 中显示图像......但它为所有图像显示相同的图像......方法如下......

- (MMGridViewCell *)gridView:(MMGridView *)gridView cellAtIndex:(NSUInteger)index
{
MMGridViewDefaultCell *cell = [[MMGridViewDefaultCell alloc] initWithFrame:CGRectNull];
cell.textLabel.text = [NSString stringWithFormat:@"Cell %d", index];
    cell.imageView.image = [UIImage imageNamed:@"cell-image.png"];
 // this needs to be change load from the array
}


- (NSInteger)numberOfCellsInGridView:(MMGridView *)gridView
{
return 64;
}

现在我有一个图像数组,需要放入该cellAtIndex方法,但是我应该怎么做才能将所有图像转换为数组中的那个..

数组就像

-(void)viewDidLoad{
_imageDatas = [DelegateClass mag]._imageData;
_finaImages = [[NSMutableArray alloc]init];
}
_finaImages = [[NSMutableArray alloc]init];
for (int i = 0; i < [_imageDatas count]; i++) {

    [_finaImages addObject:[self loadImage:i]];
}

- (UIImage *)loadImage:(int)index {
@try {
    UIImage* image = [[UIImage alloc] initWithData:[_imageDatas objectAtIndex:index]] ;

    return image;
 }
@catch (NSException *exception) {
    NSLog(@"ImageFullScreenViewController - loadImage Exception Name = %@ Exception Reason = %@",[exception name],[exception reason]);
  }

如何将数据从下面的数组转换为上面的 imageView.image

4

3 回答 3

2

尝试这个

- (MMGridViewCell *)gridView:(MMGridView *)gridView cellAtIndex:(NSUInteger)index
{
MMGridViewDefaultCell *cell = [[MMGridViewDefaultCell alloc] initWithFrame:CGRectNull];
cell.textLabel.text = [NSString stringWithFormat:@"Cell %d", index];
    cell.imageView.image =[imagesArray objectAtIndex: index];
 // this needs to be change load from the array
}
于 2013-03-22T05:32:52.867 回答
2

替换这个:

cell.imageView.image = [UIImage imageNamed:@"cell-image.png"];

和:

cell.imageView.image = (UIImage *)[_finaImages objectAtIndex:index];
于 2013-03-22T05:33:05.677 回答
1
- (MMGridViewCell *)gridView:(MMGridView *)gridView cellAtIndex:(NSUInteger)index
{
    MMGridViewDefaultCell *cell = [[MMGridViewDefaultCell alloc] initWithFrame:CGRectNull];
    cell.textLabel.text = [NSString stringWithFormat:@"Cell %d", index];
    // Use this
    cell.imageView.image = [self loadImage:index];
}
于 2013-03-22T05:33:01.310 回答