我正在使用iCarousel和我的应用程序来显示Parse的卡片
我有以下代码,但它始终会崩溃并显示以下消息
*** 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 :(得分:0)
您必须实施以下方法:
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view;
和
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel;