Reputation: 2243
i'm loading bunch of images in coverflow using i carousel but i'm not getting it?..initially i got Signal sigabart issue..after i edited some of the code the view gets displayed...Am i missing something?...
#import "CollectionViewController.h"
@interface CollectionViewController ()
@property (nonatomic, retain) NSMutableArray *items;
@end
@implementation CollectionViewController
@synthesize carousel;
@synthesize items;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
carousel.delegate = nil;
carousel.dataSource = nil;
[items release];
[carousel release];
[super dealloc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
carousel.type = iCarouselTypeCoverFlow2;
}
- (void)viewDidUnload
{
[super viewDidUnload];
self.carousel = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark -
#pragma mark iCarousel methods
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return [items count];
}
- (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel
{
return 29;
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
//create new view if no view is available for recycling
if (view == nil)
{
view = [NSArray arrayWithObjects:[UIImage imageNamed:@"gal1.jpg"],
[UIImage imageNamed:@"gal2.jpg"],
[UIImage imageNamed:@"gal3.jpg"],
[UIImage imageNamed:@"gal5.jpg"],
[UIImage imageNamed:@"gal6.jpg"],
[UIImage imageNamed:@"gal7.jpg"],
[UIImage imageNamed:@"gal8.jpg"],
[UIImage imageNamed:@"gal9.jpg"],
[UIImage imageNamed:@"gal10.jpg"],
[UIImage imageNamed:@"gal11.jpg"],
[UIImage imageNamed:@"gal12.jpg"],
[UIImage imageNamed:@"gal13.jpg"],
[UIImage imageNamed:@"gal14.jpg"],
[UIImage imageNamed:@"gal15.jpg"],
[UIImage imageNamed:@"gal16.jpg"],
[UIImage imageNamed:@"gal17.jpg"],
[UIImage imageNamed:@"gal18.jpg"],
[UIImage imageNamed:@"gal19.jpg"],
[UIImage imageNamed:@"gal20.jpg"],
[UIImage imageNamed:@"gal21.jpg"],
[UIImage imageNamed:@"gal22.jpg"],
[UIImage imageNamed:@"gal23.jpg"],
[UIImage imageNamed:@"gal24.jpg"],
[UIImage imageNamed:@"gal25.jpg"],
[UIImage imageNamed:@"gal26.jpg"],
[UIImage imageNamed:@"gal27.jpg"],
[UIImage imageNamed:@"gal28.jpg"],
}
else {
}
return view;
}
@end
while running on simulator i just get the screen not images?...i got stuck here....
Upvotes: 2
Views: 2023
Reputation: 2092
iCarousel working code:
Delegate method:
- (UIView *)carousel:(__unused iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view{
if (view == nil){
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 400 , 600)];
((UIImageView *)view).image = [UIImage imageNamed:[imageCarosualArray objectAtIndex:index]];
view.contentMode = UIViewContentModeCenter;
[view.layer setMasksToBounds:YES];
}
return view;
}
Multiple images in Array
CarosualArray =[[NSMutableArray alloc]initWithObjects:@"test1.png",@"test2.png",@"test3.png",@"test4.png",@"test5.png",@"test6.png",@"test7.png",@"test8.png",@"test9.png", nil];
Upvotes: 1
Reputation: 2466
I have done this already. Here try this:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//set up carousel data
wrap = NO;
self.items = [NSArray arrayWithObjects:[UIImage imageNamed:@"gal1.jpg"],
[UIImage imageNamed:@"gal2.jpg"],
[UIImage imageNamed:@"gal3.jpg"],
[UIImage imageNamed:@"gal5.jpg"],
[UIImage imageNamed:@"gal6.jpg"],
[UIImage imageNamed:@"gal7.jpg"],
[UIImage imageNamed:@"gal8.jpg"],
[UIImage imageNamed:@"gal9.jpg"],
[UIImage imageNamed:@"gal10.jpg"],
[UIImage imageNamed:@"gal11.jpg"],
[UIImage imageNamed:@"gal12.jpg"],
[UIImage imageNamed:@"gal13.jpg"],
[UIImage imageNamed:@"gal14.jpg"],
[UIImage imageNamed:@"gal15.jpg"],
[UIImage imageNamed:@"gal16.jpg"],
[UIImage imageNamed:@"gal17.jpg"],
[UIImage imageNamed:@"gal18.jpg"],
[UIImage imageNamed:@"gal19.jpg"],
[UIImage imageNamed:@"gal20.jpg"],
[UIImage imageNamed:@"gal21.jpg"],
[UIImage imageNamed:@"gal22.jpg"],
[UIImage imageNamed:@"gal23.jpg"],
[UIImage imageNamed:@"gal24.jpg"],
[UIImage imageNamed:@"gal25.jpg"],
[UIImage imageNamed:@"gal26.jpg"],
[UIImage imageNamed:@"gal27.jpg"],
[UIImage imageNamed:@"gal28.jpg"],nil];
}
return self;
}
Then in your:
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{
UIView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[items objectAtIndex:index]]];
return view;
}
Oh, and another one, kindly edit your numberOfVisibleItemsInCarousel
and set it to return 7;
so it doesnt waste memory, I think.
Upvotes: 1