用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;
}
怎么样能让网格图片正常显示多个图片?
你在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
}
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。