我正在点击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;
}
}
需要更改开始按钮标题以停止以及何时再次停止以启动.Vice Versa
答案 0 :(得分: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";
}
}