Konsy Konsy - 1 year ago 83
iOS Question

iCarousel won't load images

So i'm trying to use iCarousel to display products in the form of images which the user can then simply scroll and see all the products available.

For some reason when you load the viewcontroller it doesn't display any images at all or even show the carousel, it worked before when I was using it with the number int etc.

My code is as followed:


#import "ApparelViewController.h"

@interface ApparelViewController ()

@property (nonatomic, strong) NSMutableArray *images;


@implementation ApparelViewController

@synthesize carouselView = _carouselView;
@synthesize images = _images;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
//get image paths
NSArray *imagePaths = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:@"Products"];

//preload images (although FXImageView can actually do this for us on the fly)
_images = [[NSMutableArray alloc] init];
for (NSString *path in imagePaths)
[_images addObject:[UIImage imageWithContentsOfFile:path]];
return self;

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

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithRed:236/255 green:240/255 blue:241/255 alpha:1];

// Do any additional setup after loading the view.
_carouselView.type = iCarouselTypeRotary;

- (void)viewDidUnload
[super viewDidUnload];
//free up memory by releasing subviews
self.carouselView = nil;

- (NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel
return [_images count];

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
if (view == nil)
FXImageView *imageView = [[FXImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.asynchronous = YES;
imageView.reflectionScale = 0.5f;
imageView.reflectionAlpha = 0.25f;
imageView.reflectionGap = 10.0f;
imageView.shadowOffset = CGSizeMake(0.0f, 2.0f);
imageView.shadowBlur = 5.0f;
imageView.cornerRadius = 10.0f;
view = imageView;
//show placeholder
((FXImageView *)view).processedImage = [UIImage imageNamed:@"page.png"];

((FXImageView *)view).image = _images[index];

return view;

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

- (IBAction)goBack:(id)sender {

NSString * storyboardName = @"Main";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"navBar"];
[self presentViewController:vc animated:YES completion:nil];


Then in the
file I have the following code:

#import <UIKit/UIKit.h>
#import "iCarousel.h"
#import "FXImageView.h"

@interface ApparelViewController : UIViewController <iCarouselDelegate, iCarouselDelegate>

@property (strong, nonatomic) IBOutlet UIButton *backButton;
@property (strong, nonatomic) IBOutlet iCarousel *carouselView;


What's really annoying is I have used iCarousel before but for Swift so I know how it works there but I don't know Obj-C that well!

Any ideas on how I can go about displaying the images?

Answer Source

A few things you could check,

  1. Check 'images' is return a value great than 0 in 'numberOfItemsInCarousel', obvious but worth checking.
  2. Check that the image is actually loaded, i.e. check image[index] actually loads the image.
  3. I'm not that familiar with FXImageView, but try use (void)setImage:(UIImage *)image; instead of assigning @property (nonatomic, strong) UIImage *image;. The documentation says that .image doesn't actually set the image but add effects.

If none of these solve your problem, please comment and I'll keep looking, good luck.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download