1

我在点击 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;
    }

 }

在此处输入图像描述

需要更改开始按钮标题以停止,并在再次停止时开始。Vice Versa

4

1 回答 1

14

您可以使用以下代码更改文本。尝试在 .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";

    }

}
于 2013-09-09T06:37:29.343 回答