如何在objective-c中传递完井区块的参数
我试图声明一个包含几个块的函数,当我从viewdidload方法调用该函数时,这些参数的执行应该是一致的如何在objective-c中传递完井区块的参数,objective-c,function,parameters,Objective C,Function,Parameters,我试图声明一个包含几个块的函数,当我从viewdidload方法调用该函数时,这些参数的执行应该是一致的 -(void) alertViewOn:(UILabel*)LabelTextX :(UIButton*)ButtonA :(UIButton*)ButtonB :(UIImage*)ImageX { UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Enter Pet Name" messa
-(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;按钮A至按钮4;ButtonY到button5,ImageX到image2。我对objective-c完全陌生,甚至发现声明一个函数都很困难!!!请任何好心人帮忙
-(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];
}
创建_块变量,以在块方法中分配变量和访问权限