4

I am trying to achieve a right to left iCarousel object with a fade on both sides.

So i imported the GtiHub Project into My application, Assigned a UIView to iCarousel...Linked that to an IBOutLet on my MainViewController and passed the Delegate as well as the DataSource just like the UITableViewController.

Though it will not show up and i am unsure of what could be causing this issue.

My iCarousel DataSource is is an NSMutableArray *items; designed like so:

for (int i = 0; i < 100; i++)
{
    [_items addObject:@(i)];
}

I am initializing the iCarousel in the ViewDidLoad like below

- (void)viewDidLoad
{
  [super viewDidLoad];
  //Initialize Carousel
  _carousel = [[iCarousel alloc] init];
  _carousel.delegate = self;
  _carousel.dataSource = self;

  //Carousel Testing Data
  for (int i = 0; i < 100; i++)
  {
     [_items addObject:@(i)];
  }

  //configure carousel
  _carousel.type = iCarouselTypeRotary;

}

My Delegate Methods for Carousel are below:

#pragma mark -
#pragma mark iCarousel methods

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
   //return the total number of items in the carousel
   return [_items count];
}

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
   UILabel *label = nil;

   //create new view if no view is available for recycling
   if (view == nil)
   {
      view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];
      ((UIImageView *)view).image = [UIImage imageNamed:@"page.png"];
      view.contentMode = UIViewContentModeCenter;

      label = [[UILabel alloc] initWithFrame:view.bounds];
      label.backgroundColor = [UIColor clearColor];
      label.font = [label.font fontWithSize:50];
      label.tag = 1;
      [view addSubview:label];
   }
  else
   {
      //get a reference to the label in the recycled view
      label = (UILabel *)[view viewWithTag:1];
   }


  label.text = [_items[index] stringValue];
  return view;
}

 - (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
 {
    switch (option)
    {
       case iCarouselOptionFadeMin:
           return -0.2;
       case iCarouselOptionFadeMax:
           return 0.2;
       case iCarouselOptionFadeRange:
           return 2.0;
       default:
           return value;
     }
  }

Everything from the storyboard seems to be connected and the data should be presenting itself, what is wrong and how can i fix this issue?

Pawan Rai
  • 3,434
  • 4
  • 32
  • 42
Keeano
  • 309
  • 8
  • 33

4 Answers4

7

Since you have the DataSource array (_items) setup after the view gets loaded:

  1. Make sure that the carousel view in your storyboard does have the IBOutlet to the controller, but NOT the 'Delegate' and 'DataSource' linked to the File's Owner (Controller or view).

  2. Set the _carousel.delegate and _carousel.dataSource to 'self' only After you initialize and update the dataSource array (_items in this case).

instaable
  • 3,449
  • 2
  • 24
  • 31
0

Place breakpoints to check whether the iCarousel Datasource and Delegate methods are being called or not. If the methods are not called, check whether the controller follows the iCarousel protocols like this:

    @interface yourViewController : UIViewController <iCarouselDataSource, iCarouselDelegate>

Obviously you'll have to

   #import "iCarousel.h"
instaable
  • 3,449
  • 2
  • 24
  • 31
  • Those both are set up as well as the delegate and datasource, i already applied breakpoints and they showed up – Keeano Jul 30 '14 at 08:53
0

UPDATE: In your viewDidLoad, you have

  _carousel = [[iCarousel alloc] init];

looks like you forgot to set a frame for _carousel and add it as a subView.

instaable
  • 3,449
  • 2
  • 24
  • 31
  • I have a UIView on the Storyboard and connected it via IBOutlet, would that still have to be added as a subview? – Keeano Jul 30 '14 at 09:00
  • If you already have it in Controller scene with an IBOutlet, there is no need of _carousel = [[iCarousel alloc] init]; This creates a new instance of iCarousel and your _carousel will point to the new instance, which is not added as a subView, nor does it have a frame. – instaable Jul 30 '14 at 09:06
  • okay, so i took the init out of there and it still isnt showing up – Keeano Jul 30 '14 at 09:09
0

To get the imageView reference, try this:

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];
imageView.image = [UIImage imageNamed:@"page.png"];
view = imageView;
instaable
  • 3,449
  • 2
  • 24
  • 31