【问题标题】:handling Button Event in iphone处理 iphone 中的按钮事件
【发布时间】:2012-03-26 06:07:57
【问题描述】:

我创建了一个下拉类,用于在单击按钮上弹出一个窗口,它工作正常,但有一个问题是我如何处理它返回索引的事件(在为它自己的按钮选择的 tableview 的弹出窗口上) 我在那里搞错了什么?有人指导我该怎么做吗??

这里的代码..

 -(IBAction)popupOnClikingButton:(id)sender{

if (sender == button1) {
    arrayData = [[NSMutableArray alloc] initWithArray:[NSMutableArray arrayWithObjects:@"Test1",@"Test2",nil]];
   dropDownView = [[DropDownView alloc] initWithArrayData:arrayData cellHeight:30 heightTableView:150 paddingTop:-3 paddingLeft:-1 paddingRight:-1 refView:button1 animation:BLENDIN openAnimationDuration:2 closeAnimationDuration:2];
    dropDownView.delegate = self;
    [dropDownView openAnimation];
    [self.view addSubview:dropDownView.view];
    return;

}
if (sender == button2) {
    [arrayData release];
     arrayData = [[NSMutableArray alloc] initWithArray:[NSMutableArray arrayWithObjects:@"Demo1",@"Demo2",nil]];

    dropDownView = [[DropDownView alloc] initWithArrayData:arrayData cellHeight:30 heightTableView:150 paddingTop:-3 paddingLeft:-1 paddingRight:-1 refView:button1 animation:BLENDIN openAnimationDuration:2 closeAnimationDuration:2];

    dropDownView.delegate = self;
    [dropDownView openAnimation];
    [self.view addSubview:dropDownView.view];
    return;
}
}

return index DropDownDelegate 方法是.. 我如何处理这个事件,即 returnIndex 的哪个按钮??

-(void)dropDownCellSelected:(NSInteger)returnIndex{

 //set for title that which button is selected here for Ex.
[button1 setTitle:[arrayData objectAtIndex:returnIndex] forState:UIControlStateNormal];
}   

【问题讨论】:

  • 这里的人无法理解您的问题,这就是您投反对票的原因...提高您的问题质量。
  • 你的英文听不懂。
  • 不抱歉,只是重写问题。

标签: iphone objective-c ios ios4 uibutton


【解决方案1】:

尝试获取这样的按钮:

UIButton* myButton = (UIButton*)sender;

并将此按钮与您想要的按钮进行比较............

【讨论】:

    【解决方案2】:

    您还可以为按钮分配标签。有了这个,您可以使用标签与您的按钮进行比较。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-12
      • 2021-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-16
      • 1970-01-01
      相关资源
      最近更新 更多