Ios 如何在单击时更改UIActionSheet按钮标题?

Ios 如何在单击时更改UIActionSheet按钮标题?,ios,objective-c,uiactionsheet,Ios,Objective C,Uiactionsheet,我在点击UIbutton时显示UIActionSheet UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"Clock" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Start",@"Reset",nil]; [actionSheet setTag:1001]; [actionSh

我在点击UIbutton时显示UIActionSheet

UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"Clock" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Start",@"Reset",nil];
[actionSheet setTag:1001];
[actionSheet showInView:self.view];

[actionSheet release];
我想在单击时更改第一个开始按钮的标题

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
 {
    switch (buttonIndex) 
    {
        case 0:
        {
          // I want to change title of first button start to stop. on clicking.
        }
           break;
        case 1:
        {

        }
          break;
        default:
            break;
    }

 }

需要将“开始”按钮标题更改为“停止”,并在再次停止时更改为“开始”。反之亦然,您可以使用以下代码更改文本。 尝试在.m文件中实现

@interface AudioPlayerDemoViewController ()
{
UIActionSheet *action;
NSString *titleString;
}
@end

@implementation AudioPlayerDemoViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    titleString = @"Start";
    // Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)actionSheetTap:(id)sender
{
    action = [[UIActionSheet alloc]initWithTitle:@"Demo" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:titleString,@"Stop", nil];
    [action showFromBarButtonItem:sender animated:YES];

}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];

    if([title isEqual: @"Start"])
    {
        action = nil;
        titleString = @"Pause";

    }
    if([title isEqual: @"Pause"])
    {
        action = nil;
        titleString = @"Start";

    }

}

您可以使用以下代码更改文本。 尝试在.m文件中实现

@interface AudioPlayerDemoViewController ()
{
UIActionSheet *action;
NSString *titleString;
}
@end

@implementation AudioPlayerDemoViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    titleString = @"Start";
    // Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)actionSheetTap:(id)sender
{
    action = [[UIActionSheet alloc]initWithTitle:@"Demo" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:titleString,@"Stop", nil];
    [action showFromBarButtonItem:sender animated:YES];

}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];

    if([title isEqual: @"Start"])
    {
        action = nil;
        titleString = @"Pause";

    }
    if([title isEqual: @"Pause"])
    {
        action = nil;
        titleString = @"Start";

    }

}

你的问题是…?我编辑了问题,我的问题是如何更改标题?第一个按钮是行动表中的第一个按钮,是吗?零索引的按钮,先生。嗯,看起来你不能;UIActionSheet仅提供读取按钮标题的方法。我想苹果公司会觉得,一旦显示了行动表,按钮标题就会改变,这会让人困惑。你的问题是……?我编辑了问题,我的问题是如何改变标题?第一个按钮是行动表中的第一个按钮,是吗?零索引的按钮,先生。嗯,看起来你不能;UIActionSheet仅提供读取按钮标题的方法。我想苹果会觉得如果在显示动作表后按钮标题发生变化会让人困惑。你是对的,我也在想类似的事情。太好了。你是对的,我也在想类似的事情。太好了。