Friday, 30 August 2013

iCarousel does not show the picture from directory

iCarousel does not show the picture from directory

I am using the iCarousel to display my image, but strangely I did the
codes right and nothing appears. I am trying to display image from the
directory folder. In the directory folder I have few folders that have
image saved in it. Is there something missing? I am almost there and I
can't do it. I want directory Tops to display in carousel 1 and directory
Bottoms to display in the carousel 2. I don't know why this is happening.
This is my code for implementation Please feel free to ask for more code
if you want to see more. I have worked around the clock to do this, and I
cannot do it right. ANy help is appreciated.. There is a guy who says this
is a duplicate but it is not since I wan not able to get an answer by the
previous question.. The questions is not identical.
#import "iCarouselExampleViewController.h"
@interface iCarouselExampleViewController ()
@property (nonatomic, retain) NSMutableArray *items1;
@property (nonatomic, retain) NSMutableArray *items2;
@end
@implementation iCarouselExampleViewController
@synthesize carousel1;
@synthesize carousel2;
@synthesize items1;
@synthesize items2;
- (void)awakeFromNib
{
//set up data sources
self.items1 = [NSMutableArray array];
for (int i = 0; i < 100; i++)
{
[items1 addObject:[NSNumber numberWithInt:i]];
}
self.items2 = [NSMutableArray array];
for (int i = 65; i < 65 + 58; i++)
{
[items2 addObject:[NSString stringWithFormat:@"%c", i]];
}
}
- (void)dealloc
{
//it's a good idea to set these to nil here to avoid
//sending messages to a deallocated viewcontroller
carousel1.delegate = self;
carousel1.dataSource = self;
carousel2.delegate = self;
carousel2.dataSource = self;
}
#pragma mark -
#pragma mark View lifecycle
-(void)viewDidLoad
{
[super viewDidLoad];
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSFileManager *fileManager = [NSFileManager defaultManager];
//configure carousel1
NSString *fPath = [documentsDirectory
stringByAppendingPathComponent:@"Tops"];
NSArray *directoryContent = [fileManager directoryContentsAtPath: fPath];
imageArray1 = [directoryContent mutableCopy];
//configure carousel2
fPath = [documentsDirectory stringByAppendingPathComponent:@"Bottoms"];
directoryContent = [fileManager directoryContentsAtPath:fPath];
imageArray2 = [directoryContent mutableCopy];
carousel1.type = iCarouselTypeLinear;
carousel2.type = iCarouselTypeLinear;
}
- (void)viewDidUnload
{
[super viewDidUnload];
//free up memory by releasing subviews
self.carousel1 = nil;
self.carousel2 = nil;
}
#pragma mark -
#pragma mark iCarousel methods
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
//return the total number of items in the carousel
if (carousel == carousel1)
{
return [imageArray1 count];
}
else
{
return [imageArray2 count];
}
}
- (UIView *)carousel:(iCarousel *)carousel
viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{ // <--- This brace was missing!!
if (view == nil)
{
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f,
200.0f)];
UIImage *image;
if (carousel == carousel1)
{
image = [UIImage imageWithContentsOfFile:[imageArray1
objectAtIndex:index]];
((UIImageView *)view).image = image;
}
else
{
image = [UIImage imageWithContentsOfFile:[imageArray2
objectAtIndex:index]];
((UIImageView *)view).image = image;
}
return view;
}
else {
UIImage *image;
if (carousel == carousel2)
{
image = [UIImage imageWithContentsOfFile:[imageArray1
objectAtIndex:index]];
((UIImageView *)view).image = image;
}
else
{
image = [UIImage imageWithContentsOfFile:[imageArray2
objectAtIndex:index]];
((UIImageView *)view).image = image;
}
}
return view;
}
- (CGFloat)carousel:(iCarousel *)carousel
valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
//customize carousel display
switch (option)
{
case iCarouselOptionSpacing:
{
if (carousel == carousel2)
{
//add a bit of spacing between the item views
return value * 1.05f;
}
}
default:
{
return value;
}
}
}

No comments:

Post a Comment