ios – UICollectionViewController黑屏

ios – UICollectionViewController黑屏,第1张

概述我试图显示我的收藏视图,但我得到的只是一个黑屏.我知道我在某个地方遗失了一些东西,但我似乎无法找到它是什么. #import "StoreCollectionViewController.h"#import "StoreItemCell.h"@interface StoreCollectionViewController ()@property (nonatomic, strong) N 我试图显示我的收藏视图,但我得到的只是一个黑屏.我知道我在某个地方遗失了一些东西,但我似乎无法找到它是什么.

#import "StoreCollectionVIEwController.h"#import "StoreItemCell.h"@interface StoreCollectionVIEwController ()@property (nonatomic,strong) NSMutableArray *productsArray;@property (nonatomic,strong) UIActivityIndicatorVIEw *loadingIndicator;@end@implementation StoreCollectionVIEwControllerstatic Nsstring * const reuseIDentifIEr = @"Cell";- (ID)initWithNibname:(Nsstring *)nibnameOrNil bundle:(NSBundle *)nibBundleOrNil{    self = [super initWithNibname:nibnameOrNil bundle:nibBundleOrNil];    if (self)    {        self.productsArray = [[NSMutableArray alloc]init];    }    return self;}- (voID)vIEwDIDLoad {    [super vIEwDIDLoad];    self.collectionVIEw.delegate = self;    self.collectionVIEw.dataSource = self;    // Register cell classes    [self.collectionVIEw registerClass:[StoreItemCell class] forCellWithReuseIDentifIEr:reuseIDentifIEr];    CGfloat wIDth = CGRectGetWIDth(self.vIEw.bounds);    CGfloat height = CGRectGetHeight(self.vIEw.bounds);    self.loadingIndicator = [[UIActivityIndicatorVIEw alloc]initWithFrame:CGRectMake(wIDth / 2,height / 2,37,37)];    self.loadingIndicator.center = CGPointMake(wIDth / 2,height / 2 - 37);    self.loadingIndicator.autoresizingMask = (UIVIEwautoresizingFlexibleRightmargin | UIVIEwautoresizingFlexibleleftmargin | UIVIEwautoresizingFlexibleBottommargin | UIVIEwautoresizingFlexibletopmargin);    self.loadingIndicator.activityIndicatorVIEwStyle = UIActivityIndicatorVIEwStyleWhiteLarge;    self.loadingIndicator.hIDesWhenStopped = YES;    [self.vIEw addSubvIEw:self.loadingIndicator];    [self.loadingIndicator startAnimating];    [self dispatch];}- (voID)dIDReceiveMemoryWarning {    [super dIDReceiveMemoryWarning];    // dispose of any resources that can be recreated.}- (voID)dispatch {    NSURL *url = [NSURL URLWithString:@"http://API.bigcartel.com/littleheart/products.Json"];    dispatch_async(dispatch_get_global_queue(disPATCH_QUEUE_PRIORITY_DEFAulT,0),^{        NSData *data = [NSData dataWithContentsOfURL:url];        dispatch_async(dispatch_get_main_queue(),^{            if (data == nil) {                NSLog(@"data is nil");                UIAlertVIEw *nilDataAlert = [[UIAlertVIEw alloc]initWithTitle:@"" message:@"There is nothing here!" delegate:self cancel@R_301_5554@Title:@"OK" other@R_301_5554@Titles:nil,nil];                [nilDataAlert show];                [self.loadingIndicator stopAnimating];            }            else {                [self performSelectorOnMainThread:@selector(getProducts:) withObject:data waitUntilDone:YES];            }        });    });}- (voID)getProducts:(NSData *)responseData {    NSError *error;    NSMutableArray *responseArray = [NSJsONSerialization                                     JsONObjectWithData:responseData                                     options:kNilOptions                                     error:&error];    for (NSDictionary *productDictionary in responseArray) {        [self.productsArray addobject:productDictionary];    }    [self.collectionVIEw reloadData];    [self.loadingIndicator stopAnimating];}#pragma mark <UICollectionVIEwDataSource>- (NSInteger)numberOfSectionsInCollectionVIEw:(UICollectionVIEw *)collectionVIEw {    return 1;}- (NSInteger)collectionVIEw:(UICollectionVIEw *)collectionVIEw numberOfItemsInSection:(NSInteger)section {    return self.productsArray.count;}- (UICollectionVIEwCell *)collectionVIEw:(UICollectionVIEw *)collectionVIEw cellForItemAtIndexPath:(NSIndexPath *)indexPath {    StoreItemCell *cell = [collectionVIEw dequeueReusableCellWithReuseIDentifIEr:reuseIDentifIEr forIndexPath:indexPath];    // Configure the cell    Nsstring *productname = [[self.productsArray objectAtIndex:indexPath.row]objectForKey:@"name"];    cell.itemnameLabel.text = productname;    return cell;}#pragma mark <UICollectionVIEwDelegate>- (voID)collectionVIEw:(UICollectionVIEw *)collectionVIEw dIDSelectItemAtIndexPath:(NSIndexPath *)indexPath {}@end
解决方法 您是否使用UICollectionVIEwDelegateFlowLayout方法来调整单元格大小.?

像这样(这是在Swift中,使用Objective-C syntex),

func collectionVIEw(collectionVIEw: UICollectionVIEw,layout collectionVIEwLayout: UICollectionVIEwLayout,sizeforItemAtIndexPath indexPath: NSIndexPath) -> CGSize{    return CGSizeMake(50,120); //use whatever you wants.}
总结

以上是内存溢出为你收集整理的ios – UICollectionViewController黑屏全部内容,希望文章能够帮你解决ios – UICollectionViewController黑屏所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1044837.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存