i want to display multiple images in a view controller using iCarousel.
i list all my images in NSMutableArray foto,
and then i called the array foto in iCarousel method viewForItemAtIndex.
i've followed some tutorial but still doesn't work.
please help me.
here's my .m code
#import "TestController.h"
@interface TestController () <UIActionSheetDelegate>
@property (nonatomic, retain) NSMutableArray *foto;
@end
@implementation TestController
@synthesize carousel;
@synthesize foto;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
foto = [NSArray arrayWithObjects:
[UIImage imageNamed:@"Seleb1.jpg"],
[UIImage imageNamed:@"Seleb2.jpg"],
[UIImage imageNamed:@"Seleb3.jpg"],
nil];
}
return self;
}
- (void)dealloc
{
carousel.delegate = nil;
carousel.dataSource = nil;
}
- (void)viewDidLoad
{
[super viewDidLoad];
carousel.type = iCarouselTypeCoverFlow2;
}
- (void)viewDidUnload
{
[super viewDidUnload];
self.carousel = nil;
}
#pragma mark -
#pragma mark iCarousel methods
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return [foto count];
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[foto objectAtIndex:index]]];
return view;
}
@end
can someone help me ? what is wrong with my code ?
Updated Code
#import "TestController.h"
@interface TestController ()
@property (nonatomic, retain) NSArray *foto;
@end
@implementation TestController
@synthesize carousel;
@synthesize foto;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
foto = [NSArray arrayWithObjects:
@"Seleb1.jpg",
@"Seleb2.jpg",
@"Seleb3.jpg",
nil];
}
return self;
}
- (void)dealloc
{
carousel.delegate = nil;
carousel.dataSource = nil;
}
- (void)viewDidLoad
{
[super viewDidLoad];
carousel.type = iCarouselTypeCoverFlow2;
[carousel reloadData];
}
- (void)viewDidUnload
{
[super viewDidUnload];
self.carousel = nil;
}
#pragma mark -
#pragma mark iCarousel methods
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return [foto count];
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view {
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)]; // set the frame for your Image
UIImage *image = [UIImage imageNamed:[foto objectAtIndex:index]];
((UIImageView *)view).image = image;
return view;
}
- (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
//customize carousel display
return value+0.1;
}
@end
i fix my code by combining all your answer, thankyou so much. here's my new code :
#import "TestController.h"
@interface TestController ()
@property (nonatomic, retain) NSArray *foto;
@end
@implementation TestController
@synthesize carousel;
@synthesize foto;
- (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;
}
- (void)viewDidLoad
{
carousel.delegate = self;
carousel.dataSource = self;
foto = [NSArray arrayWithObjects:
@"Seleb1.jpg",
@"Seleb2.jpg",
@"Seleb3.jpg",
nil];
[super viewDidLoad];
carousel.type = iCarouselTypeCoverFlow2;
[carousel reloadData];
}
- (void)viewDidUnload
{
[super viewDidUnload];
self.carousel = nil;
}
#pragma mark -
#pragma mark iCarousel methods
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
NSLog(@"%lu",(unsigned long)foto.count);
return [foto count];
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view {
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)]; // set the frame for your Image
UIImage *image = [UIImage imageNamed:[foto objectAtIndex:index]];
((UIImageView *)view).image = image;
return view;
}
- (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
//customize carousel display
return value+0.1;
}
@end
Thank you so much for all your answer, i really appreciate it :)