3

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

4

2 回答 2

0

像这样设置 iCarousel 的 DataSource 和 Delegate

在此处输入图像描述

而不是在 .h 文件中为您的 iCarousel 设置您的 ViewController 代表

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

@interface iCarouselViewController : UIViewController<iCarouselDataSource, iCarouselDelegate>

@property (strong, nonatomic) NSMutableArray *images;
@property (nonatomic, retain) IBOutlet iCarousel *carousel;

@end

didSelectItemAtIndex并在 .m 文件中像这样编写委托方法

    -(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];

}
于 2013-06-06T06:11:08.977 回答
0

一旦这样尝试,

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{

        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[menuViews objectAtIndex:index]]];
        _reflectionView =[[[ReflectionView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, image.size.width, image.size.height)] autorelease];
        UIButton *button = [[[UIButton alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)] autorelease];
        [button setBackgroundImage:image forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        button.titleLabel.font = [button.titleLabel.font fontWithSize:14];
        [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
        button.tag = index;
        [_reflectionView addSubview:button];

    return _reflectionView;
}

在上面的代码 menuViews 是图像数组。

- (void)buttonTapped:(UIButton *)sender
{   
    NSLog(@"%d",sender.tag);//based on tag value you can do whatever you want
}
于 2013-06-06T05:32:19.317 回答