Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIAlertAction-设置UIAlertAction后编辑它_Ios_Objective C_Uialertcontroller - Fatal编程技术网

Ios UIAlertAction-设置UIAlertAction后编辑它

Ios UIAlertAction-设置UIAlertAction后编辑它,ios,objective-c,uialertcontroller,Ios,Objective C,Uialertcontroller,我有一个名为ManagerClass的类 Manager类有一个函数showUIAlertController: - (UIAlertController*)showUIAlertController:(NSString *)title message:(NSString *)message actions:(NSArray<UIAlertAction*>* )actions “performTheAction”并不存在——它只是让你理解我试图实现的目标 有人知道如何完成这项任务

我有一个名为ManagerClass的类

Manager类有一个函数showUIAlertController:

- (UIAlertController*)showUIAlertController:(NSString *)title  message:(NSString *)message actions:(NSArray<UIAlertAction*>* )actions
“performTheAction”并不存在——它只是让你理解我试图实现的目标

有人知道如何完成这项任务吗

在查看苹果的UIAlertAction API时没有找到这样做的方法
您的意思是执行代码提供的方法吗。然后使用:

[self performSelector:@selector(aMethod:)];
或在发送对象时使用:

[self performSelector:@selector(aMethod:)
       withObject:(id)object];
注意,这里的self引用的是同一个类,它也可能在其他地方

  • 编辑*

    UIAlertController*alert=[UIAlertController alertControllerWithTitle:@“我的警报” 消息:@“这是一个警报。” 首选样式:UIAlertControllerStyleAlert]

    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { 
               NSLog(@"42.");
               }];
    
    [alert addAction:defaultAction];
    [self presentViewController:alert animated:YES completion:nil];
    

控制台注销42。把你需要的每一个动作都放进去。

你的意思是执行你的代码提供的方法吗。然后使用:

[self performSelector:@selector(aMethod:)];
或在发送对象时使用:

[self performSelector:@selector(aMethod:)
       withObject:(id)object];
注意,这里的self引用的是同一个类,它也可能在其他地方

  • 编辑*

    UIAlertController*alert=[UIAlertController alertControllerWithTitle:@“我的警报” 消息:@“这是一个警报。” 首选样式:UIAlertControllerStyleAlert]

    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { 
               NSLog(@"42.");
               }];
    
    [alert addAction:defaultAction];
    [self presentViewController:alert animated:YES completion:nil];
    

控制台注销42。把你需要的每一个动作都放进去。

为什么要调用第二个警报,只显示第一个警报并执行一些代码?您也可以在第一个警报中执行此操作


希望我理解你的意思。

为什么要调用第二个警报,只显示第一个警报并执行部分代码?您也可以在第一个警报中执行此操作


希望我对您的理解正确。

您可以传递警报操作模型,而不是
UIAlertAction

因此,您的方法如下所示:

- (UIAlertController*)showUIAlertController:(NSString *)title  message:(NSString *)message actions:(NSArray<MyActionModel*>* )actions
然后,您可以在需要时创建
UIAlertAction
s,还可以添加manager回调


另外,如果我的Objective-C不太正确,我有点生疏。

您可以传递警报操作模型,而不是
UIAlertAction

因此,您的方法如下所示:

- (UIAlertController*)showUIAlertController:(NSString *)title  message:(NSString *)message actions:(NSArray<MyActionModel*>* )actions
然后,您可以在需要时创建
UIAlertAction
s,还可以添加manager回调


请注意,如果我的Objective-C不太正确,我有点生疏。

否。我的意思是采取一个UIAlertAction,以某种方式将其复制到一个新操作中,并在该新操作中执行收到的操作+我的代码。否。我的意思是采取一个UIAlertAction,以某种方式将其复制到一个新的action中,并在该新action中执行接收到的action+我的代码。但是使用了没有输入或输出参数的“runningBlock”。通过这种方式,我可以创建一个UIAlertAction,并在其块内运行我的“runningBlock”。苹果似乎没有提供任何编辑UIAlertAction的方法。我或多或少采用了这种方法。但是使用了没有输入或输出参数的“runningBlock”。通过这种方式,我可以创建一个UIAlertAction,并在其块内运行我的“runningBlock”。苹果似乎没有提供任何编辑UIAlertAction的方法。假设您想要一个UIAlertController管理器。这样将负责防止多个警报一个接一个地显示。因此,对于每个操作,经理都希望知道警报已解除。一种可能的方法是让管理器具有以下功能:-(UIAlertController*)showUIAlertController:(NSString)title message:(NSString*)message actions:(NSArray)actions,并在管理器上创建UIAlertController,并在每个操作中添加一些代码,通知管理器已执行该操作。我希望它确实有意义:)想象一下你想要一个UIAlertController管理器。这样将负责防止多个警报一个接一个地显示。因此,对于每个操作,经理都希望知道警报已解除。一种可能的方法是让管理器具有以下功能:-(UIAlertController*)showUIAlertController:(NSString)title message:(NSString*)message actions:(NSArray)actions,并在管理器上创建UIAlertController,并在每个操作中添加一些代码,通知管理器已执行该操作。我希望这确实有点道理:)