1
votes

I'm using iCarousel library in my small app. I'm getting the image urls via web service and placing those images to the iCarousel library.

First I created a UIView and added iCarousel as respective class to it. Latter set the datasourse and delete gate to same class.

Now everything looks cool and I could see the images but I couldn't swipe the images.

Following is my code.

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    //return the total number of items in the carousel
    return [galleryItems 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)
    {
        //NSString *ImageURL = @"YourURLHere";
        //NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
        //imageView.image = [UIImage imageWithData:imageData];

        view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];

        //[((UIImageView *)view) setImageWithURL:[NSURL URLWithString:@"http://www.pizzatower.com/img/icons/Pizza-icon.png"]];
        NSURL *imageURL = [[galleryItems objectAtIndex:index] galleryURL];
        [((UIImageView *)view) setImageWithURL:imageURL];

        view.contentMode = UIViewContentModeScaleAspectFit;
        label = [[UILabel alloc] init];
        label.backgroundColor = [UIColor clearColor];
        label.font = [label.font fontWithSize:20];
        label.tag = 1;
        // label.contentMode = UIViewContentModeBottom;
        //        label.frame = CGRectMake(
        //                                       self.view.frame.size.width - label.frame.size.width,
        //                                       self.view.frame.size.height - label.frame.size.height,
        //                                       label.frame.size.width,
        //                                       label.frame.size.height );
        //label.bounds = view.bounds;
        [view addSubview:label];
    }
    else
    {
        //get a reference to the label in the recycled view
        label = (UILabel *)[view viewWithTag:1];
    }

    //set item label
    //remember to always set any properties of your carousel item
    //views outside of the `if (view == nil) {...}` check otherwise
    //you'll get weird issues with carousel item content appearing
    //in the wrong place in the carousel
    //label.text = [[galleryItems objectAtIndex:index] galleryDescription];

    return view;
}

I've used same code base and it worked in some other project. No idea what am I missing here. Can someone please enlighten me.

2
please add the code related to the initialization of the carousel... Also, check whether the userinteraction is enabled, and there is no layer on top of the carousel..ZeMoon

2 Answers

1
votes

You UIView containing the carousel may have userInteractionEnabled set to NO.

Another possibility is that the UIView containing the carousel may be smaller than the carousel and so be blocking interaction. Try setting its background color to see its true size.

0
votes

I'd suggest delete your nib or the ViewController in your storyboard and re-create it. I had the same issue once and after re-creating it it worked. Make sure you center your UIView when placing it (both horizontally and vertically)