我有一个名为ManagerClass的类。
Manager类有一个函数showUIAlertController:
- (UIAlertController*)showUIAlertController:(NSString *)title message:(NSString *)message actions:(NSArray<UIAlertAction*>* )actions此函数应显示带有接收到的参数的报警控制器。
到目前为止一切顺利..。
现在我想采取这些行动,并以某种方式编辑它们。类似于:
UIAlertAction *action = actions.firstObject;
UIAlertAction *actionCopyWithAdditionalAction = [UIAlertAction actionWithTitle:action.title style:action.style handler:^(UIAlertAction * _Nonnull action) {
[action "performTheAction"]; //perform the original action
[ManagerClass doSomething];
}];"performTheAction“并不存在--它只是让你理解我想要实现的目标。
有谁知道如何完成这项任务吗?
在查看苹果的UIAlertAction应用程序接口https://developer.apple.com/reference/uikit/uialertaction时,我没有找到这样做的方法
发布于 2017-02-21 18:24:33
您的意思是执行您的代码提供的方法。然后使用:
[self performSelector:@selector(aMethod:)];或者在使用以下命令发送对象时:
[self performSelector:@selector(aMethod:)
withObject:(id)object];请注意,这里的self引用的是同一个类,它也可以在其他地方。
UIAlertController* alert = UIAlertController alertControllerWithTitle:@“我的警报”消息:@“这是一个警报。”首选样式:UIAlertControllerStyleAlert;
UIAlertAction* defaultAction = UIAlertAction动作addAction:@“确定”样式:UIAlertAction默认处理程序:^(UIAlertAction*动作){ NSLog(@"42.");};报警添加动作:默认动作;自呈现presentViewController:报警动画:YES presentViewController
控制台退出42。取而代之的是你需要的每一个动作。
发布于 2017-02-21 19:11:22
您可以传递警报操作模型,而不是UIAlertAction。
所以你的方法看起来像这样:
- (UIAlertController*)showUIAlertController:(NSString *)title message:(NSString *)message actions:(NSArray<MyActionModel*>* )actions其中MyActionModel是一个具有3个属性的类
@interface MyActionModel: NSObject {
@property NSString * title;
@property UIAlertActionStyle * style;
@property ((void)^(UIAlertAction *)) action;
}然后,您可以在需要时创建UIAlertAction,也可以添加到管理器回调中。
另外,如果我的Objective-C不太正确,很抱歉,我有点生疏了。
https://stackoverflow.com/questions/42364608
复制相似问题