I have a ViewController1 with a UILabel that can present a ViewController2 with a Modal Segue. I have a UITextField in ViewController2 that I need to access from ViewController1 so I can set my UILabel with the collected text.
I've tried working with the prepareForSegue without success. What should I do?
EDIT:
I'm using a Delegate, but I'm doing something wrong. Here's the code I'm using in ViewController2.h:
@class ViewController2;
@protocol VCProtocol
-(void)setName:(NSString *)name;
@end
@interface ViewController2 : UIViewController
@property (nonatomic, weak) id<VCProtocol> delegate;
@property (strong, nonatomic) IBOutlet UITextField *nameField;
- (IBAction)setButton:(id)sender
@end
ViewController2.m
-(IBAction)setButton:(id)sender
{
[self.delegate setName:nameField.text];
}
I conform to VCProtocol in my ViewController1.h. Then, in my ViewController1.m, I have this code:
- (void)setName:(NSString *)name
{
self.firstSignatureNameLabel.text = name;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqual:@"Sign"])
{
ViewController2 *VC = [segue destinationViewController];
VC.delegate = self;
}
}