UIcollection 视图未获取呼叫数据源 [英] UIcollection view not getting call datasources

查看:19
本文介绍了UIcollection 视图未获取呼叫数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我从 xib 创建了一个 UICollectionView.这是我的 .h

Hello Im creating a UICollectionView from xib. And this is my .h class

@interface ArtistViewController : <UIViewController<UICollectionViewDataSource,UICollectionViewDelegate>

@property (retain, nonatomic) IBOutlet UICollectionView *collectionview;

在我的 .m ViewDidloadmethod 我做了这个

in my .m ViewDidloadmethod I did this

[collectionview setBackgroundColor:[UIColor clearColor]];

我的数据源和代表是这样的

My data sources and delegates are like this

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [dataArray count];
}



- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView {
return 1;
}





 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"CollectionViewCell";

CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];


//artist = [arrayClass.mutArrayArtists objectAtIndex:indexPath.row];
UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:100];
if([[dataArray objectAtIndex:indexPath.row] valueForKey:@"thumbImage"]!=nil){


    recipeImageView.image=[[dataArray objectAtIndex:indexPath.row] valueForKey:@"thumbImage"];
}
else
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSURL *imageURL = [NSURL URLWithString:[[dataArray objectAtIndex:indexPath.row] valueForKey:@"thumbUrl"]];
        NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
        UIImage *image = [UIImage imageWithData:imageData];
        dispatch_async(dispatch_get_main_queue(), ^{
            if(image!=nil){
                NSMutableDictionary *objectDict=[[NSMutableDictionary alloc] initWithDictionary:[dataArray objectAtIndex:indexPath.row]];
                [objectDict setObject:image forKey:@"thumbImage"];
                [dataArray replaceObjectAtIndex:indexPath.row withObject:objectDict];
            }

            recipeImageView.image= image;

        });
    });
}



UILabel *lblArtistname=(UILabel *)[cell viewWithTag:102];
lblArtistname.text=[[dataArray objectAtIndex:indexPath.row] valueForKey:@"name"];

lblArtistname.lineBreakMode=NSLineBreakByWordWrapping;
[lblArtistname setNumberOfLines:0];

CGSize maximumLabelSize = CGSizeMake(300,800);
CGSize expectedLabelSize = [[lblArtistname text] sizeWithFont:lblArtistname.font
                                            constrainedToSize:maximumLabelSize
                                                lineBreakMode:[lblArtistname lineBreakMode]];
CGRect newframe=lblArtistname.frame;
newframe.size.height=expectedLabelSize.height;
newframe.size.width=300;
[lblArtistname setFrame:newframe];


//UILabel *lblSongCount=(UILabel *)[cell viewWithTag:101];
// lblSongCount.text=artist.numberofSongs;
return cell;
}

但这不会调用任何数据源方法.这是为什么.我该如何解决这个问题.请帮帮我.

But this not getting call for any datasource method. Why is that. How can I solve this. Please help me.

谢谢

推荐答案

在 .m ViewDidloadmethod 中添加这个

In .m ViewDidloadmethod add this

[self.collectionview setDelegate:self];
[self.collectionview setDataSource:self];

并更正第一行的错字:

@interface ArtistViewController :    UIViewController<UICollectionViewDataSource,UICollectionViewDelegate>

这篇关于UIcollection 视图未获取呼叫数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆