我需要根据标志值禁用alerview索引。
我的观点是:
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:@"Reminder" message:@"Send a reminder through" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[alert addButtonWithTitle:@"Email"];
[alert addButtonWithTitle:@"SMS"];
[alert addButtonWithTitle:@"TS"];
[alert addButtonWithTitle:@"Cancel"];
[alert show];
我有一个名为isCheck = 0或1
的标志如果isCheck = 1我必须禁用名为SMS的按钮索引。任何人都可以帮忙
答案 0 :(得分:1)
您可以尝试的内容如下代码所示:
只有当isCheck为1时才会添加短信按钮。
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:@"Reminder" message:@"Send a reminder through" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[alert addButtonWithTitle:@"Email"];
if (isCheck==1) {
[alert addButtonWithTitle:@"SMS"];
}
[alert addButtonWithTitle:@"TS"];
[alert addButtonWithTitle:@"Cancel"];
[alert show];
将以下委托方法添加到您的代码中,以处理UIAlertView
的特定按钮点击的任何内容:
- (void)alertView:(UIAlertView *)alert didDismissWithButtonIndex:(NSInteger)buttonIndex {
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Email"])
{
NSLog(@"Email");
}
if([title isEqualToString:@"SMS"])
{
NSLog(@"SMS");
}
if([title isEqualToString:@"TS"])
{
NSLog(@"TS");
}
if([title isEqualToString:@"Cancel"])
{
NSLog(@"Cancel");
}
}
OR
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Email"])
{
//Email button Clicked: Do whatever you want
NSLog(@"Email");
}
if([title isEqualToString:@"SMS"])
{
//SMS button Clicked: Do whatever you want
NSLog(@"SMS");
//Call your Web Service
if(isCheck==1){
//Do something
}
else{
//Do Nothing
}
}
if([title isEqualToString:@"TS"])
{
//TS button Clicked: Do whatever you want
NSLog(@"TS");
}
if([title isEqualToString:@"Cancel"])
{
//Cancel button Clicked: Do whatever you want
NSLog(@"Cancel");
}
}