HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – collectionView:cellForItemAtIndexPath:永远不会被调用大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个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 plac@R_674_8371@: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 *imag@R_674_8371@Descriptor = [NSSortDescriptor sortDescriptorWithKey:@"imag@R_674_8371@" ascending:YES];
    NSArray *sortedJotImages = [jotImages sortedArrayUsingDescriptors:@[imag@R_674_8371@Descriptor]];
    */
    //###
}


#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方法中@L_607_9@了collectionView registerClass:forCellWithReusEIDentifier.

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

我希望这有帮助.

大佬总结

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

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。