2014-01-31 80 views
0
我使用iCarousel

與我的應用從解析iCarousel不顯示圖片來自解析

顯示卡

我有以下的代碼,但它始終與下面的消息崩潰

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber objectForKey:]: unrecognized selector sent to instance 0x9b07590' 

我試過同結構集合視圖,它工作正常,但我不能iCarousol集成到代碼

任何一個可以幫助我,什麼是錯過

代碼

@implementation carousolViewController 

@synthesize cardData, cardFileArray,carousel, items; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)awakeFromNib 
{ 
    //set up data 
    //your carousel should always be driven by an array of 
    //data of some kind - don't store data in your item views 
    //or the recycling mechanism will destroy your data once 
    //your item views move off-screen 
    self.cardFileArray = [NSMutableArray array]; 
    for (int i = 0; i < 1000; i++) 
    { 
     [cardFileArray addObject:[NSNumber numberWithInt:i]]; 
    } 
} 

- (void)dealloc 
{ 
    //it's a good idea to set these to nil here to avoid 
    //sending messages to a deallocated viewcontroller 
    carousel.delegate = nil; 
    carousel.dataSource = nil; 
} 


- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 

    self.title = cardData.themeNames; 

    carousel.type = iCarouselTypeCoverFlow2; 

    [self queryParseMethod]; 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 

    //free up memory by releasing subviews 
    self.carousel = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return YES; 
} 


- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

-(void)queryParseMethod { 

    if ([self.title isEqualToString:@"Birthday Cards"]) { 

     PFQuery *query = [PFQuery queryWithClassName:WALL_OBJECT3]; 
     if (cardFileArray == 0) { 
      query.cachePolicy = kPFCachePolicyCacheThenNetwork; 

     } 

     [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
      if (!error) { 
       cardFileArray = [[NSMutableArray alloc] initWithArray:objects]; 
       [iCarousel load]; 
      } 
     }]; 

    } else if ([self.title isEqualToString:@"Love Cards"]) { 

     PFQuery *query = [PFQuery queryWithClassName:WALL_OBJECT2]; 
     if (cardFileArray == 0) { 
      query.cachePolicy = kPFCachePolicyCacheThenNetwork; 

     } 

     [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
      if (!error) { 
       cardFileArray = [[NSMutableArray alloc] initWithArray:objects]; 
       [iCarousel load]; 
      } 
     }]; 

    } else if ([self.title isEqualToString:@"Islamic Cards"]) { 

     PFQuery *query = [PFQuery queryWithClassName:WALL_OBJECT]; 
     if (cardFileArray == 0) { 
      query.cachePolicy = kPFCachePolicyCacheThenNetwork; 

     } 

     [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
      if (!error) { 
       cardFileArray = [[NSMutableArray alloc] initWithArray:objects]; 
       [iCarousel load]; 
      } 
     }]; 

    } 
} 


#pragma mark - 
#pragma mark iCarousel methods 

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel 
{ 
    //return the total number of items in the carousel 
    return [cardFileArray count]; 
} 


- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view 
{ 

     if (view == nil) 
    { 

     view = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300.0f, 300.0f)] autorelease]; 
    } 


     PFObject *imageObject = [cardFileArray objectAtIndex:index]; 
     PFFile *imageFile = [imageObject objectForKey:KEY_IMAGE4]; 


    [imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) { 
      if (!error) { 

       ((UIImageView *)view).image = [UIImage imageWithData:data]; 
       view.contentMode = UIViewContentModeCenter; 



      } 




     }]; 




    return view; 
} 



@end 

回答

0

您必須實現以下方法:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view; 

和:

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel;