Ios 从添加到UIAlertViewController的UIAlertAction工作表中获取所选按钮标题

Ios 从添加到UIAlertViewController的UIAlertAction工作表中获取所选按钮标题,ios,objective-c,Ios,Objective C,我使用Objective-C创建了操作表。当我想要获取所选按钮标题时,我被卡住了。请帮帮我。 (我知道有一种委托方法可以获取操作的标题,但在iOS 8.0+中不推荐使用。) 这是我的代码。我的要求是获取所选标题并将其更新为文本字段 NSArray *subjectType = [NSArray arrayWithObjects:@"Customer Service",@"Product Info",@"Deals",@"Special",@"Others", nil]; UIAlert

我使用Objective-C创建了操作表。当我想要获取所选按钮标题时,我被卡住了。请帮帮我。 (我知道有一种委托方法可以获取操作的标题,但在iOS 8.0+中不推荐使用。) 这是我的代码。我的要求是获取所选标题并将其更新为文本字段

NSArray *subjectType = [NSArray arrayWithObjects:@"Customer Service",@"Product Info",@"Deals",@"Special",@"Others", nil];

    UIAlertController *subjectSheet = [UIAlertController alertControllerWithTitle:@"Subjects" message:@"Select a prefered subject" preferredStyle:UIAlertControllerStyleActionSheet];


    for (int i=0; i<subjectType.count; i++) {
        UIAlertAction *myalertAction = [UIAlertAction actionWithTitle:[subjectType objectAtIndex:i] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

        }];


    [subjectSheet addAction:myalertAction];
}
NSArray*subjectType=[NSArray数组,其对象为:@“客户服务”@“产品信息”@“交易”@“特殊”@“其他”,无];
UIAlertController*subjectSheet=[UIAlertController alertControllerWithTitle:@“主题”消息:@“选择首选主题”首选样式:UIAlertControllerStyleActionSheet];

对于(int i=0;i请尝试
UIAlertAction的title属性

 UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"Title"
                                                               message:@"message"
                                                        preferredStyle:UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction actionWithTitle:@"OK"
                                          style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                                              NSLog(@"%@",action.title);
                                          }]];
[self presentViewController:alert animated:true completion:nil];

您可以执行以下操作来实现您想要实现的目标

NSArray *subjectType = [NSArray arrayWithObjects:@"Customer Service",@"Product Info",@"Deals",@"Special",@"Others", nil];

UIAlertController *subjectSheet = [UIAlertController alertControllerWithTitle:@"Subjects" message:@"Select a prefered subject" preferredStyle:UIAlertControllerStyleActionSheet];


for (int i=0; i<subjectType.count; i++) {
    UIAlertAction *myalertAction = [UIAlertAction actionWithTitle:[subjectType objectAtIndex:i] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
          [self takeActionAccordingToString:action.title];
    }];


[subjectSheet addAction:myalertAction];
[self presentViewController:subjectSheet animated:YES completion:nil];
}
-(void)takeActionAccordingToString:(NSString *)actionTitle{
if([actionTitle isEqualToString:[yourArray objectAtIndex:0]]){
//you can take action here
}
if([actionTitle isEqualToString:[yourArray objectAtIndex:1]]){
//you can take action here
}
if([actionTitle isEqualToString:[yourArray objectAtIndex:2]]){
//you can take action here
}
if([actionTitle isEqualToString:[yourArray objectAtIndex:3]]){
//you can take action here
}
if([actionTitle isEqualToString:[yourArray objectAtIndex:4]]){
//you can take action here
}
//etc....
}
NSArray*subjectType=[NSArray数组,其对象为:@“客户服务”@“产品信息”@“交易”@“特殊”@“其他”,无];
UIAlertController*subjectSheet=[UIAlertController alertControllerWithTitle:@“主题”消息:@“选择首选主题”首选样式:UIAlertControllerStyleActionSheet];

对于(int i=0;i
UIActionSheet
类本身在iOS 8中已被弃用。请向我们展示您的代码。获取标题的意义是什么?如果您可以解释以便我们可以回答correctly@ozgur,我编辑了我的问题。你可以看到我的code@SyedAliSalman我想用所选的按钮标题更新一个文本字段。所以我需要得到你能检查一下我的回答是否让你满意吗?