我试图在其中声明一个包含几个块的函数,当我从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中是全新的,甚至宣布一个函数也很困难!请任何善良的人帮助......
答案 0 :(得分:0)
-(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];
}