【问题标题】:button action touchup inside doesn't work properly内部的按钮动作修饰无法正常工作
【发布时间】:2015-11-12 12:57:47
【问题描述】:

viewcontroller.h 文件

@interface ViewController : UIViewController<kDropDownListViewDelegate>
 {
 NSArray *arryList;
 NSArray *arryList1;
 DropDownListView * Dropobj;
 }

- (IBAction)DropDownPressed:(id)sender;

- (IBAction)DropDownPressed1:(id)sender;

@property (strong, nonatomic) IBOutlet UILabel *lblSelectedCountryNames;


@property (strong, nonatomic) IBOutlet UILabel *lblSelectedCountryNames1;
@end

viewcontroller.m 文件

- (void)viewDidLoad 
{

[super viewDidLoad];


arryList=@[@"India",@"Swaziland",@"Africa",@"Australlia",@"Pakistan"];


arryList1=@[@"India1",@"Swaziland1",@"Africa1",@"Australlia1",@"Pakistan"];    

}
 - (void)DropDownListView:(DropDownListView *)dropdownListView didSelectedIndex:(NSInteger)anIndex
{
/*----------------Get Selected Value[Single selection]-----------------*/
    _lblSelectedCountryNames.text=[arryList objectAtIndex:anIndex];
    _lblSelectedCountryNames1.text=[arryList1 objectAtIndex:anIndex];

}
 - (IBAction)DropDownPressed:(id)sender 
{
[Dropobj fadeOut];
[self showPopUpWithTitle:@"Select Country" withOption:arryList xy:CGPointMake(16, 58)     size:CGSizeMake(287, 330) isMultiple:NO];
}
- (IBAction)DropDownPressed1:(id)sender 
{
[Dropobj fadeOut];
[self showPopUpWithTitle:@"Select " withOption:arryList1 xy:CGPointMake(16, 58)     size:CGSizeMake(287, 330) isMultiple:NO];
}

单击 DropDownPressed1 时,它不会与 arrylist1 一起加载……而不是与 arrylist 一起加载……如果我选择 valaue 示例 india……这就是两个标签中显示的值。 ....如何纠正这些问题...如果不清楚,请提供您的邮箱 ..我会提前发送我的示例项目...

【问题讨论】:

  • 检查DropDownPressed1DropDownPressed的连接。你试过调试吗?
  • 如果我同时单击按下的按钮操作...加载相同的 arrylist 并且如果我选择值 ....相似的值将显示在两个标签中..如何填充正确的数组列表并在标签中显示正确的值。
  • 你确定它同时进入 DropDownPressed1 和 DropDownPressed 吗?
  • @ anhtu 是的,我检查了连接...现在它已正确加载但现在如果我选择印度,则单击下拉菜单...它也会自动显示在 _lblSelectedCountryNames1 中...如何避免这种情况...
  • - (void)DropDownListView:(DropDownListView *)dropdownListView didSelectedIndex:(NSInteger)anIndex { /*----------------Get Selected Value[Single selection]-----------------*/ _lblSelectedCountryNames.text=[arryList objectAtIndex:anIndex]; _lblSelectedCountryNames1.text=[arryList1 objectAtIndex:anIndex]; } 随意修改这个函数。如果您点击 DropDownPressed1 或 DropDownPressed,您可以使用 1 个变量进行检查。

标签: ios cocoa-touch uibutton


【解决方案1】:

更多按钮和标签:

    @interface ViewController : UIViewController<kDropDownListViewDelegate>
     {
     NSArray *arryList;
     NSArray *arryList1;
     DropDownListView * Dropobj;

     int iTappedBtn;
     }


    - (void)DropDownListView:(DropDownListView *)dropdownListView didSelectedIndex:(NSInteger)anIndex
    {
    /*----------------Get Selected Value[Single selection]-----------------*/
         switch (iTappedBtn){
           case 0:
           {
            _lblSelectedCountryNames.text=[arryList objectAtIndex:anIndex];
           } 
           case 1: 
           {
            _lblSelectedCountryNames1.text=[arryList1 objectAtIndex:anIndex];
           }
           // and so on: 
           // case ...
         }
    }
     - (IBAction)DropDownPressed:(id)sender 
    {
    iTappedBtn = 0;

    [Dropobj fadeOut];
    [self showPopUpWithTitle:@"Select Country" withOption:arryList xy:CGPointMake(16, 58)     size:CGSizeMake(287, 330) isMultiple:NO];
    }
    - (IBAction)DropDownPressed1:(id)sender 
    {
    iTappedBtn = 1;

    [Dropobj fadeOut];
    [self showPopUpWithTitle:@"Select " withOption:arryList1 xy:CGPointMake(16, 58)     size:CGSizeMake(287, 330) isMultiple:NO];
    }
    // and so on for other DropDownPressed

这不是很好。但简单易懂。

【讨论】:

  • 是的,兄弟,它工作得很好......我如何检查我是否有三个标签......还有一件事......对于在 dropdownpressed 值中选择的值进行更改dropdownpressed1 和 dropdownpressed2 .....但是我在 dropdownpressed1 值中选择要在 dropdownpressed1 中更改的值,只有它不会改变其他人..怎么做..bro
  • 我不明白你的所有问题。但我会再次编辑我的答案。
  • 是的,一切正常......我有一个疑问......或需要......如果我点击 dropdownpressed1......值应该改变,只有不在 dropdownpressed2 中。 ..有可能..意味着..怎么做?
  • 案例 1:{_lblSelectedCountryNames.text=[arryList1 objectAtIndex:anIndex]; _lblSelectedCountryNames1.text=[arryList1 objectAtIndex:anIndex]; }
  • 你可以使用 switch case 做你想做的事
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-07
  • 1970-01-01
  • 2015-01-31
  • 1970-01-01
  • 2018-07-24
  • 2013-11-11
  • 2017-03-15
相关资源
最近更新 更多