1

UIボタンのタップで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;
    }

 }

ここに画像の説明を入力

開始ボタンのタイトルを変更して停止し、停止したときに再び開始する必要があります。その逆

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 に答える