Search code examples
iosicarousel

How to select an image in Carousel and go to next view in iPhone


I'm making an iPhone app which consists of carousel. Please can anyone tell how we perform an action on selected image of Carousel.

- (void)carousel:(iCarousel *)crsl didSelectItemAtIndex:(NSInteger)index { }

I'm trying to implement this but its not giving correct result please can anyone tell correct implementation of this

thanks


Solution

  • Set the DataSource and Delegate of iCarousel like this

    enter image description here

    And than in .h file set your ViewController Delegate for your iCarousel

    #import <UIKit/UIKit.h>
    #import "iCarousel.h"
    
    @interface iCarouselViewController : UIViewController<iCarouselDataSource, iCarouselDelegate>
    
    @property (strong, nonatomic) NSMutableArray *images;
    @property (nonatomic, retain) IBOutlet iCarousel *carousel;
    
    @end
    

    And in .m file write the delegate method didSelectItemAtIndex like this

        -(void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index
    {
    
        UIImage * img = [images objectAtIndex:index];
    
        ImageViewController *aImageViewController = [[ImageViewController alloc] initWithNibName:@"ImageViewController" bundle:nil];
    
        aImageViewController.image = img;   //this code is used to send image to another view not tested
    
        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:aImageViewController];
        navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
    
    //this code used for present second-view controller that display selected image
        navigationController.topViewController.title = @"Greeting's";
        [self presentModalViewController:navigationController               animated:YES];
        [navigationController release];
    
    }