collectionview无法显示图像

时间:2016-01-21 10:31:04

标签: objective-c image url uicollectionview

我为旅行者制作了一个应用程序,用户必须选择旅行活动。出于这个原因,我进行了collectionview,但是我在第一次创建一个新文件masterviewcontroller时遇到错误,并且声明如下所示并在customcolumncell.h文件中输出并使断点符号出错,因此..在objectforkey中显示错误: activityimage

{
NSMutableArray *myObject;
NSDictionary *dict;
NSString *activity_id;
NSString *activity_image;
}
-(void)viewDidLoad
{
[super viewDidLoad];
activity_id=@"Activity_ID";
activity_image= @"Activity_Image";
myObject = [[NSMutableArray alloc]init];
NSData *jsonData=[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://ezpacking.wowartndecor.com/api/Activity?Activity_id=0"]];
id jsonObjects = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
NSDictionary *arrdic=(NSDictionary *)jsonObjects;
NSMutableArray *arrdata=[arrdic objectForKey:@"Data"];
for (NSDictionary *dataDict in arrdata)
{
NSString *strActivity_ID=[dataDict objectForKey:@"Activity_ID"];
NSString *strActivity_Image=[dataDict objectForKey:@"Activity_Image"];
dict=[NSDictionary dictionaryWithObjectsAndKeys:strActivity_ID,activity_id,strActivity_Image,activity_image,nil];
[myObject addObject:dict];
}
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return myObject.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomColumnCell *myCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"myCell"forIndexPath:indexPath];
NSDictionary *tmpDict = [myObject objectAtIndex:indexPath.row];
NSURL *url=[NSURL URLWithString:[tmpDict objectForKey:activity_image]];
NSData *data=[NSData dataWithContentsOfURL:url];
UIImage *img=[[UIImage alloc]initWithData:data];
myCell.imageview.image = img;
return myCell;
}

0 个答案:

没有答案