我试图声明一个带有几个块的函数,当我从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的新手,即使声明一个函数也很难!!!请任何仁慈的人帮忙....
-(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] 删除。
我来说两句