【问题标题】:Button select event for iCarousel app in iOSiOS 中 iCarousel 应用的按钮选择事件
【发布时间】:2013-05-02 04:58:26
【问题描述】:

我将 iCarousel 集成到我的应用程序中。它工作正常。但我的要求是在单个视图中显示两个按钮以及这两个按钮的特定操作。我将按钮显示为

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

我们可以使用

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

全视图选择。但是如何设置这两个按钮的两个具体动作呢?

提前致谢。

【问题讨论】:

标签: ios6 uibutton icarousel


【解决方案1】:

在创建项目视图时将按钮操作绑定到视图控制器,然后在操作方法中使用轮播的 indexForViewOrSubview: 方法来确定按下了哪个按钮。

如果您使用笔尖创建视图,请查看 iCarousel 示例项目中包含的控件示例,了解如何执行此操作。

【讨论】:

    【解决方案2】:

    你为什么不试试这个:

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

    同样,

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

    相应地在事件中:

    - (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
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 2011-03-21
      • 2017-11-27
      • 1970-01-01
      相关资源
      最近更新 更多