Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iCarousel Not Showing up and Method not being handled

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?

like image 408
Keeano Avatar asked Mar 19 '23 21:03

Keeano


1 Answers

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).

like image 139
instaable Avatar answered Apr 01 '23 02:04

instaable