2012-10-24 16 views
5

कहा जाता है मेरे पास एक UICollectionView है और मैं बस इसे दिखाना चाहता हूं। मेरे पास इंटरफेस बिल्डर में फ़ाइल के मालिक से जुड़ा प्रतिनिधि और डेटासोर्स है।संग्रह दृश्य: cellForItemAtIndexPath: कभी भी

collectionView:numberOfItemsInSection: 

बस ठीक कहलाता है।

मैं इस के साथ कुछ घंटों के लिए खिलवाड़ किया गया है और अभी यह पता नहीं कर सकते हैं ...

किसी भी मदद की बहुत अच्छा होगा, अग्रिम धन्यवाद!

यहां पूर्ण स्रोत है। क्षमा करें अगर इसकी थोड़ी गन्दा है।

ज फ़ाइल

#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 

मीटर फ़ाइल

#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 

उत्तर

2

मैं एक ऐसी ही समस्या हो रही थी। cellForItemAtIndexPath नहीं कहा जा रहा था। कई मिनटों के लिए अपने बालों को खींचने के बाद, मैंने viewDidLoad विधि से collectionViewregisterClass:forCellWithReuseIdentifier हटा दिया।

ऐसा करने के बाद, cellForItemAtIndexPath कॉल करना शुरू हुआ।

मुझे उम्मीद है कि इससे मदद मिलती है।

+1

यह मेरे लिए भी चाल है। अजीब बग जो था। – AncientAnvil

2

मैं एक ऐसी ही समस्या थी और यहां मेरे समाधान किया गया था:

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

नहीं बुलाया जा रहा था itemSize की वजह से था collectionViewFlowLayout की ऊंचाई के लिए बहुत बड़ी थी।

[self.myCollectionViewFlowLayout setItemSize:CGSizeMake(320, 548)]; 

यदि मैं ऊंचाई को 410 में बदलता हूं, तो यह सेलफोरइटम एट इंडेक्सपैथ निष्पादित करेगा।

+0

मेरा दिन बचाया! धन्यवाद। – Drux

1

मुझे पता चला कि मुझे गलत सेटअप कस्टम फ्लो लेआउट क्लास था जिससे मुझे समस्याएं आईं। फ़्लो लेआउट पर वापस लाया और यह ठीक काम किया।

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^