开发者社区> 问答> 正文

关于iphone中UIGridView的问题

用UIGridView创了一个网格视图的图片,但是用下面的代码之后,实现的效果是只有一张图片显示了所有的网格:

-(UIGridViewCell *) gridView:(UIGridView *)grid cellForRowAt:(int)rowIndex AndColumnAt:(int)columnIndex
{
Cell *cell = (Cell *)[grid dequeueReusableCell];

if (cell == nil) {
    cell = [[Cell alloc] init];
}


NSString *imageLink = [item objectForKey:@"link"];

NSURL * imageURL = [NSURL URLWithString:imageLink];
NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage * image = [UIImage imageWithData:imageData];

cell.thumbnail.image = image;
return cell;
}

怎么样能让网格图片正常显示多个图片?

展开
收起
爵霸 2016-03-26 09:45:49 1822 0
1 条回答
写回答
取消 提交回答
  • 你在gridView中cellForRowAt方法把相同的链接给所有的UIGridViewCell.

    应该根据owIndex和列指数来给出不同链接,才能显示出不同图片

    比如,每行有四个图片

     int column = 4;
     int row = totalImage / column;
    
     for(int i=1; i<=totalImage; i++)
     {
        for(int j=1; j<=row; j++)
        {
           for(int m=1; m<=column; m++)
           {
              // j and m 's image
           }
        }
     }
    2019-07-17 19:15:23
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载