ios – collectionView:cellForItemAtIndexPath:永远不会被调用

ios – collectionView:cellForItemAtIndexPath:永远不会被调用,第1张

概述我有一个UICollectionView,我只是希望它出现.我在委托接口构建器中将委托和数据源附加到文件的所有者. collectionView:numberOfItemsInSection: 获得调用就好了. 我一直在搞乱这几个小时,只是想不出来…… 任何帮助都会很棒,提前谢谢! 这是完整的来源.对不起,如果它有点凌乱. .h文件 #import <UIKit/UIKit.h>#import 我有一个UICollectionVIEw,我只是希望它出现.我在委托接口构建器中将委托和数据源附加到文件的所有者.

collectionVIEw:numberOfItemsInSection:

获得调用就好了.

我一直在搞乱这几个小时,只是想不出来……

任何帮助都会很棒,提前谢谢!

这是完整的来源.对不起,如果它有点凌乱.

.h文件

#import <UIKit/UIKit.h>#import <MapKit/MapKit.h>#import "PinAnnotation.h"#import "Jot.h"@interface JotCardVIEwController : UIVIEwController <MKMapVIEwDelegate,UICollectionVIEwDataSource,UICollectionVIEwDelegateFlowLayout>@property (nonatomic,strong) Jot* jot;@end

.m文件

#import "JotCardVIEwController.h"#import "JotVIEwController.h"#import <QuartzCore/QuartzCore.h>@interface JotCardVIEwController ()@property (nonatomic,strong) JotVIEwController *detailVIEwController;@property (nonatomic,strong) IBOutlet UIVIEw *cardFrontVIEw;@property (nonatomic,assign,getter = isFlipped) BOol flipped;@property (nonatomic,weak) IBOutlet MKMapVIEw *mapVIEw;@property (nonatomic,strong) IBOutlet UICollectionVIEw *collectionVIEw;@property (nonatomic,weak) IBOutlet UILabel *jotTitle;@property (nonatomic,weak) IBOutlet UILabel *jotDate;@property (nonatomic,weak) IBOutlet UILabel *sunriseSunsetDelta;@property (nonatomic,weak) IBOutlet UILabel *jotNotes;@end@implementation JotCardVIEwController- (ID)initWithNibname:(Nsstring *)nibnameOrNil bundle:(NSBundle *)nibBundleOrNil{    self = [super initWithNibname:nibnameOrNil bundle:nibBundleOrNil];    if (self) {        // Custom initialization    }    return self;}- (voID)vIEwDIDLoad{    [super vIEwDIDLoad];    // Do any additional setup after loading the vIEw from its nib.    [[self mapVIEw] setRegion:MKCoordinateRegionMakeWithdistance(CLLocationCoordinate2DMake([self.jot.latitude floatValue],[self.jot.longitude floatValue]),1000,1000)];    //Todo: if there is no jot location - say that their isn't (maybe text over the map display)    CLLocation *tempLocation = [[CLLocation alloc] initWithCoordinate:CLLocationCoordinate2DMake([self.jot.latitude doubleValue],[self.jot.longitude doubleValue]) altitude:0 horizontalAccuracy:0 verticalAccuracy:0 timestamp:nil];    [self dropPin:tempLocation];    [self.collectionVIEw registerClass:[UICollectionVIEwCell class] forCellWithReuseIDentifIEr:@"Cell"];    [self.collectionVIEw reloadData];}- (voID) vIEwWillAppear:(BOol)animated{    [self refreshUIFromJot];}- (voID)dIDReceiveMemoryWarning{    [super dIDReceiveMemoryWarning];    // dispose of any resources that can be recreated.}- (IBAction)flipToDetails:(ID)sender{    if (![self isFlipped]) {        if (!self.detailVIEwController) {            JotVIEwController *jotVIEwController = [[JotVIEwController alloc] initWithNibname:@"JotVIEw" bundle:[NSBundle mainBundle]];            jotVIEwController.jot = self.jot;            self.detailVIEwController = jotVIEwController;            self.detailVIEwController.vIEw.frame = self.cardFrontVIEw.frame;            self.detailVIEwController.vIEw.layer.cornerRadius = 10.0;        }        [UIVIEw TransitionFromVIEw:self.cardFrontVIEw toVIEw:self.detailVIEwController.vIEw duration:0.33 options:UIVIEwAnimationoptionCurvelinear |UIVIEwAnimationoptionTransitionFlipFromright completion:^(BOol finished) {            [self setFlipped:YES];        }];    } else {        [UIVIEw TransitionFromVIEw:self.detailVIEwController.vIEw toVIEw:self.cardFrontVIEw duration:0.33 options:UIVIEwAnimationoptionCurvelinear |UIVIEwAnimationoptionTransitionFlipFromleft completion:^(BOol finished) {            [self setFlipped:NO];        }];    }}- (voID) setJot:(Jot *) jot {    _jot = jot;    [self refreshUIFromJot];}- (voID) refreshUIFromJot{    [[self jotTitle] setText:self.jot.summary];    [[self jotDate] setText:self.jot.recorddate];    [[self jotNotes] setText:self.jot.note];    [[self sunriseSunsetDelta] setText:@""];}-(voID) dropPin: (CLLocation*)newLocation{    for (ID<MKAnnotation> pin in self.mapVIEw.annotations){        MKAnnotationVIEw* anVIEw = [self.mapVIEw vIEwForAnnotation: pin];        if (anVIEw){            [self.mapVIEw removeAnnotation:pin];            NSLog(@"Pin removed");        }    }    PinAnnotation *pin = [[PinAnnotation alloc] initWithCoordinates:newLocation.coordinate placename:nil description:nil];    [self.mapVIEw addAnnotation:pin];}#pragma  mark - MKMapVIEwDelegate methods- (voID) mapVIEwDIDFinishLoadingMap:(MKMapVIEw *)mapVIEw{    NSLog(@"Map!");}#pragma mark - UICollectionVIEw DataSource- (NSInteger)collectionVIEw:(UICollectionVIEw *)vIEw numberOfItemsInSection:(NSInteger)section{    return 1;}- (UICollectionVIEwCell *)collectionVIEw:(UICollectionVIEw *)collectionVIEw cellForItemAtIndexPath:(NSIndexPath *)indexPath{    UICollectionVIEwCell *cell = [collectionVIEw dequeueReusableCellWithReuseIDentifIEr:@"Cell" forIndexPath:indexPath];    //cell.backgroundcolor = [UIcolor colorWithPatternImage:[self.results objectAtIndex:indexPath.row]];    return cell;    //###    /*    NSSet *jotimages = self.jot.images;    NSSortDescriptor *imagenameDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"imagename" ascending:YES];    NSArray *sortedJotimages = [jotimages sortedArrayUsingDescriptors:@[imagenameDescriptor]];    */    //###}#pragma mark - UICollectionVIEwDelegate- (voID)collectionVIEw:(UICollectionVIEw *)collectionVIEw dIDSelectItemAtIndexPath:(NSIndexPath *)indexPath{    // Todo: Select Item}- (voID)collectionVIEw:(UICollectionVIEw *)collectionVIEw dIDdeselectItemAtIndexPath:(NSIndexPath *)indexPath {    // Todo: deselect item}#pragma mark – UICollectionVIEwDelegateFlowLayout- (CGSize)collectionVIEw:(UICollectionVIEw *)collectionVIEw layout:(UICollectionVIEwLayout*)collectionVIEwLayout sizeforItemAtIndexPath:(NSIndexPath *)indexPath{    CGSize retval = CGSizeMake(100,100);    return retval;}- (UIEdgeInsets)collectionVIEw:(UICollectionVIEw *)collectionVIEw layout:(UICollectionVIEwLayout*)collectionVIEwLayout insetForSectionAtIndex:(NSInteger)section{    return UIEdgeInsetsMake(50,20,50,20);}@end
解决方法 我遇到了类似的问题.未调用cellForItemAtIndexPath.拔出我的头发几分钟后,我从vIEwDIDLoad方法中删除了collectionVIEw registerClass:forCellWithReuseIDentifIEr.

在这之后,cellForItemAtIndexPath开始被调用.

我希望这有帮助.

总结

以上是内存溢出为你收集整理的ios – collectionView:cellForItemAtIndexPath:永远不会被调用全部内容,希望文章能够帮你解决ios – collectionView:cellForItemAtIndexPath:永远不会被调用所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存