从u inactionsheet按钮更改解开标题

时间:2015-02-05 16:33:42

标签: ios uibutton uiactionsheet

我有一个显示uiactionsheet的uibutton。我想用uiactionsheet按钮标题替换unbutton标题。 uiactionsheet按钮显示无线电波段(AM / FM)选项。 uiactionsheet将选择乐队。然后我想要uibutton标题显示选择了哪种模式。 如何在操作表操作中添加“clickedButtonAtIndex”。

            - (IBAction)modeButton1:(id)sender
{

UIActionSheet *actionSheet2 = [[UIActionSheet alloc] initWithTitle:@"Mode Select"
                                                          delegate:self
                                                 cancelButtonTitle:@"Cancel"
                                            destructiveButtonTitle:nil
                                                 otherButtonTitles:@"FM",@"AM",nil];

 [actionSheet2 showFromRect:[(UIButton *)sender frame] inView:self.view animated:YES];
}

 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
   {
    if (buttonIndex == 0)
   {
    NSLog(@"FM mode selected");
   }
   else if (buttonIndex == 1)
   {
     NSLog(@"AM mode selected");
    }
  }

1 个答案:

答案 0 :(得分:1)

为按钮设置属性并在clickedButton中使用setTitle:ForState:,但首先检查按下的按钮是否为取消按钮。