如何在objective-c中的完成块上传递参数

阿拉芬·罗素(Arafin Russell)

我试图声明一个带有几个块的函数,当我从viewdidload方法调用该函数时,这些参数应该一致执行

-(void) alertViewOn:(UILabel*)LabelTextX :(UIButton*)ButtonA :(UIButton*)ButtonB :(UIImage*)ImageX {


UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Enter Pet Name" message:nil preferredStyle:UIAlertControllerStyleAlert];

//Show TextField
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField)
 {
     textField.placeholder = NSLocalizedString(@"Pet Name", @"Name");
 }];

//Set Ok Button
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){

    [alert dismissViewControllerAnimated:YES completion:nil];

    UITextField *textField = alert.textFields.firstObject;
    self.labelText2.text   = textField.text;

}];
[alert addAction:ok];

//Set ADD Button
UIAlertAction* addPet = [UIAlertAction actionWithTitle:@"Add More" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){

    [alert dismissViewControllerAnimated:YES completion:nil];

    self.button4.hidden = NO;
    self.button5.hidden = NO;
    self.image2.hidden = NO;

}];
[alert addAction:addPet];

//Set Cancel Button
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action){

    [alert dismissViewControllerAnimated:YES completion:nil];

}];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];
}

在这里,我想将参数LabelTextX传递给labelText2;ButtonA到button4; ButtonY到button5,ImageX到image2。我是Objective-c的新手,即使声明一个函数也很难!!!请任何仁慈的人帮忙....

阿拉芬·罗素(Arafin Russell)
-(void) alertViewOn:(UILabel*)LabelTextX :(UIButton*)ButtonA :   (UIButton*)ButtonB :(UIImageView*)ImageX {

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Enter Pet Name" message:nil preferredStyle:UIAlertControllerStyleAlert];

//Show TextField
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField)
 {
     textField.placeholder = NSLocalizedString(@"Pet Name", @"Name");
 }];

//Set Ok Button
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){

    [alert dismissViewControllerAnimated:YES completion:nil];

    UITextField *textField = alert.textFields.firstObject;
    LabelTextX.text   = textField.text;

}];

[alert addAction:ok];

//Set ADD Button
UIAlertAction* addPet = [UIAlertAction actionWithTitle:@"Add More" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){

    [alert dismissViewControllerAnimated:YES completion:nil];

    ButtonA.hidden = NO;
    ButtonB.hidden = NO;
    ImageX.hidden = NO;

}];

[alert addAction:addPet];

//Set Cancel Button
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action){

    [alert dismissViewControllerAnimated:YES completion:nil];

}];

[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];
}

然后调用这样的函数...

- (IBAction)buttonPressed15:(id)sender {
         [self alertViewOn:_labelText15 :_button30 :_button31 :_image15];
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

是否可以将完成块传递给Objective-C中的委托参数?

如何在Objective-C中传递多个参数?

如何在Objective-C iOS中等待完成块完成

如何创建与Objective-C完成块等效的C ++作为参数

如何编写一个Objective-C完成块

Worklight-如何在Objective-C中的适配器过程调用中传递参数?

如何在Objective C中存储块?

如何在Obj C中编写没有完成块的异步方法的单元测试

如何在 Objective C 中使用 CallKit

如何在objective c ios中使用multipart上传图像?

如何在.childAdded firebase查询中添加完成块?

如何在React Native中的DateTimePicker上传递参数?

如何在 FatFree 框架中的主路由上传递参数

如何在objective-c中将参数作为key和其他参数作为body传递

如何在objective-c中将block作为宏的参数传递?

如何在C ++中传递参数包?

如何在一个函数中执行两个完成块并将完成块的数据传递给下一个视图控制器?

可以从Objective-C使用的带有完成块的方法

如何在Objective c 中处理TableviewCell 中的UIButton?

如何在JPA查询上传递参数?

如何在Objective-C中创建通用属性?

如何在Objective-C中测试stdin函数?

如何在Objective C中解析Wikipedia的JSON数据?

如何在 Objective-C 中收听 Apple TV Remote?

如何在 Objective C 中创建单选按钮

如何在Objective-C宏中编写多条指令?

如何在Objective-C中忽略NSTimer TimeInterval?

如何在Objective-C中防止继承?

如何在Objective-C中模拟双重调度