简体   繁体   English

UICollectionView将不会在自定义popupview中显示单元格

[英]UICollectionView will not display cells in custom popupview

I have a UICollectionView inside a popupview which is just a simple view in a xib file. 我在popupview中有一个UICollectionView,这只是xib文件中的一个简单视图。 In the same xibfile I have my UICollectionViewCell like this: 在同一个xibfile中,我的UICollectionViewCell是这样的:

SamplePopUpViewController.xib

The View is connected to SampleViewController class and the UICollectionViewCell is connected to PekProfil class 视图连接到SampleViewController类,UICollectionViewCell连接到PekProfil类

The code I use for displaying the cells is 我用于显示单元格的代码是

    [_collectionView registerClass:[PekProfil class] forCellWithReuseIdentifier:@"vinnare"];
_collectionView.delegate = self;
_collectionView.dataSource = self;

and: 和:

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"vinnare";
    PekProfil * cellen = (PekProfil *)[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

cellen.backgroundColor = [UIColor grayColor];
if (cellen==nil) {
    cellen = [[PekProfil alloc] init];

}
NSString * iden = [_winners objectAtIndex:indexPath.row];
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                              initWithGraphPath:iden
                              parameters:nil
                              HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
    NSLog(@"fetched friends:%@", result);
    cellen.pekProfilNamn.text = [result objectForKey:@"name"];
    NSString * ideno = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?width=640&height=640", iden];
    NSLog(@"IDEN:%@", ideno);
    NSString *pictureUrl = ideno;
    NSURL * url = [NSURL URLWithString:pictureUrl];
    NSLog(@"PICURL:%@", pictureUrl);
    NSData *data = [NSData dataWithContentsOfURL:url];
    NSLog(@"%@", data);
    UIImage *img = [[UIImage alloc] initWithData:data];
    //roundpic
    CALayer *imageLayer = cellen.profilePicView.layer;
    [imageLayer setCornerRadius:5];
    [imageLayer setBorderWidth:1];
    [imageLayer setMasksToBounds:YES];
    [cellen.profilePicView.layer setCornerRadius:cellen.profilePicView.frame.size.width/2];
    [cellen.profilePicView.layer setMasksToBounds:YES];
    //END
    cellen.profilePicView.image = img;

}];

return cellen;

} }

And I know that the facebookcode works since I use the same code in other places. 而且我知道facebookcode可以工作,因为我在其他地方使用了相同的代码。

However running this only displays this: 但是,运行此命令仅显示以下内容:

在此处输入图片说明

Any ideas why the content is not displaying? 有什么想法为什么不显示内容?

You should create a custom subclass of UiCollectionViewCell. 您应该创建UiCollectionViewCell的自定义子类。 If you want to layout your cell in IB check include XIB file. 如果要在IB中布置单元格,请检查XIB文件。 It's not possible to combine classes like this in objective C. Register you nib your reuse identifier and make your image view and label public properties that you can then set in cellForItemAtIndexPath 不可能在目标C中组合这样的类。注册您的重用标识符,并使图像视图和标签公共属性,然后可以在cellForItemAtIndexPath中进行设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM