【问题标题】:UICollectionView Won't LoadUICollectionView 不会加载
【发布时间】:2017-09-25 23:53:59
【问题描述】:

我将我的 Xcode 更新为 9 并使用 iOS 11 作为 Base SDK。不知何故,当我这样做时,事情发生了变化。从那时起,我的应用程序中的集合视图就没有显示。 NSLog 永远不会在控制台中显示部分中的项目数,当我为 cellForItem 放入 NSLog 时,NSLog 也不会在控制台中触发任何内容。 XIB 中的所有内容都已正确连接,同样,这是针对 AppStore 中已经存在的应用程序,除了下载新的 Xcode 之外,我没有更改任何代码。世界上到底发生了什么?这是它的代码:

 - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];

        NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
        [self.tableView deselectRowAtIndexPath:selectedIndexPath animated:YES];

    }

    - (void)viewDidLoad
{

    [super viewDidLoad];

     arryData = [[NSArray alloc] initWithObjects:@"AIMCON", @"Devotional Songs", @"Saved Devotionals", @"AIM Series 2017", @"Resources", @"Podcasts", @"Website", @"Links",  nil];
    CALayer * l = [viewofimage layer];
    [l setMasksToBounds:YES];
    [l setCornerRadius:11];
    [l setBorderWidth:2.0];
    [l setBorderColor:[[UIColor blackColor] CGColor]];
    tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);


        [self.collectionView registerClass:[CVCell class] forCellWithReuseIdentifier:@"cvCell"];

        self.collectionView.backgroundColor = [UIColor whiteColor];


    self.collectionView.delegate = self;

    // Do any additional setup after loading the view.
}





    -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
        return 1;
        NSLog(@"1");
    }
    -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
        return [arryData count];
        NSLog(@"2");
    }

    -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
        NSLog(@"Selected");
        if (indexPath.row == 1) {
            DevoSongs *dvController = [[DevoSongs alloc] initWithNibName:@"DevoSongs" bundle:[NSBundle mainBundle]];

            [self.navigationController pushViewController:dvController animated:YES];
            [dvController release];
        }
        if (indexPath.row == 2) {
            ListOfDevos *dvController7 = [[ListOfDevos alloc] initWithNibName:@"ListOfDevos" bundle:[NSBundle mainBundle]];

            [self.navigationController pushViewController:dvController7 animated:YES];
            [dvController7 release];

        }
        if (indexPath.row == 4) {
            AIMProject *dvController7 = [[AIMProject alloc] initWithNibName:@"AIMProject" bundle:[NSBundle mainBundle]];

            [self.navigationController pushViewController:dvController7 animated:YES];
            [dvController7 release];

        }
        if (indexPath.row == 5) {
            Podcasts *dvController2 = [[Podcasts alloc] initWithNibName:@"Podcasts" bundle:[NSBundle mainBundle]];

            [self.navigationController pushViewController:dvController2 animated:YES];
            [dvController2 release];

        }
        if (indexPath.row == 6) {
            FamilyMinistry *dvController5 = [[FamilyMinistry alloc] initWithNibName:@"FamilyMinistry" bundle:[NSBundle mainBundle]];

            [self.navigationController pushViewController:dvController5 animated:YES];
            [dvController5 release];

        }
        if (indexPath.row == 7) {
            LinksViewController *dvController6 = [[LinksViewController alloc] initWithNibName:@"LinksViewController" bundle:[NSBundle mainBundle]];

            [self.navigationController pushViewController:dvController6 animated:YES];
            [dvController6 release];
        }

        if (indexPath.row == 0) {
            NSLog(@"TABLE");
            SECTable *dvController7 = [[SECTable alloc] initWithNibName:@"SECTable" bundle:[NSBundle mainBundle]];
            [self.navigationController pushViewController:dvController7 animated:YES];
            [dvController7 release];
        }
        if (indexPath.row == 3) {
            NSLog(@"AIM Series");
            AIMSeries *dvController9 = [[AIMSeries alloc] initWithNibName:@"AIMSeries" bundle:[NSBundle mainBundle]];

            [self.navigationController pushViewController:dvController9 animated:YES];
            [dvController9 release];
        }

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



        static NSString *cellIdentifier = @"cvCell";

        CVCell *cell = (CVCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];


        NSString *thearticleImage = [[arryData objectAtIndex:indexPath.row] stringByAppendingString:@".png"];
        [cell.theimage setImage:[UIImage imageNamed:thearticleImage]];
        //titleLabel2.text = entry.articleTitle;

        CALayer * l = [cell.theimage layer];
        [l setMasksToBounds:YES];
         [l setCornerRadius:11];
        [l setBorderWidth:2.0];
        [cell.labels setText:[arryData objectAtIndex:indexPath.row]];

        NSLog(@"%@", cell.labels.text);




        return cell;
    }

    @end

这是它从工作到现在的不同之处,我所做的只是更新 Xcode。 前: 后:

【问题讨论】:

  • 查找已弃用的集合视图委托方法。
  • @tomato 我重新安装了 Xcode 8,它也没有在那里加载集合视图,所以一定是在我没有意识到的情况下发生了一些变化,但至于我一无所知。
  • 不是 Xcode 9?出于什么原因,你要重新安装 Xcode 8 吗?
  • @ElTomato 最初,我认为这个问题与 iOS 11 或 Xcode 9 有关。所以,我安装了 Xcode 8 来确认。但是,在 Xcode 8 中使用 iOS 10 作为 Base SDK 时仍然存在问题,所以很明显,我最初的想法是错误的,并且无意中改变了一些东西。
  • 请尝试将arrayData声明为@property(nonatomic,retain) NSArray *arrayData;并将其用作self.arrayData

标签: ios objective-c xcode uicollectionview


【解决方案1】:

将集合视图的 isPrefetchingEnabled 属性设置为 false。

【讨论】:

  • 该属性已在 xib 文件中取消选择。
  • 我已经尝试在代码和 XIB 文件中更改集合视图的背景颜色,但在屏幕上它仍然显示为黑色,所以我什至不知道集合视图是否显示在屏幕。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-12-09
  • 2021-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多