1
votes

I integrate the iCarousel into my application.It is working fine.But my requirement is to display the two buttons in single view and specific actions for these two buttons.I display the buttons as

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

 UIView *sampleView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 250, 300)];
    sampleView.backgroundColor=[UIColor whiteColor];

UIButton*  btntrans=[UIButton buttonWithType:UIButtonTypeCustom];
    [btntrans setFrame:CGRectMake(45, 40, 105, 50)];

    [btntrans setBackgroundColor:[UIColor clearColor]];
    btntrans.titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:15];
    [btntrans setTitle:@"" forState:UIControlStateNormal];
    [btntrans setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [sampleView addSubview:btntrans]; 
UIButton*  btntrans1=[UIButton buttonWithType:UIButtonTypeCustom];
    [btntrans1 setFrame:CGRectMake(45, 90, 105, 50)];

    [btntrans1 setBackgroundColor:[UIColor clearColor]];
    btntrans1.titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:15];
    [btntrans1 setTitle:@"" forState:UIControlStateNormal];
    [btntrans1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [sampleView addSubview:btntrans1]; 
return sampleView;
}

we can use

-(void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index
{
    NSLog(@"ITEM SELECTED");
}

for whole view selection.but How to set the two specific actions for these two buttons?

Thanks in advance.

2
Try this its working for me. Try thisvijay

2 Answers

1
votes

Bind the button action to your view controller when you create the item view, then use indexForViewOrSubview: method of carousel in your action method to work out which button was pressed.

If you are using a nib to create your views, take a look at the controls example included with the iCarousel example projects for how to do this.

1
votes

Why don't you try this:

[btntrans addTarget:self
             action:@selector(first_action)
   forControlEvents:UIControlEventTouchUpInside];

Similarly,

[btntrans1 addTarget:self
              action:@selector(second_action)
    forControlEvents:UIControlEventTouchUpInside];

Correspondingly in the events:

- (void)first_action:(id)sender{

    //This will get you the index of the selected view

    NSInteger index = [self.carousel indexOfItemViewOrSubview:sender];
                 .......
    //Do whatever you feel like

}