我正在尝试将文本字段文本从一个控制器传递到另一个控制器,以便我可以通过电子邮件发送它。我正在关注一个例子,但我必须遗漏一些小细节。基本上,目标是将数据文本字段文本从 enteryournamecontroller 控制器传递到选项控制器的 nsstring。nsstring 的字符串变量返回 null。
EnterYourNameController.h
@interface EnterYourNameController : UIViewController{
UITextField *textField;
id <EnterYourNameController> delegate;
}
@property (strong, nonatomic) NSString *stringEntered;
@property (strong, nonatomic) UITextField *textField;
@property (strong, nonatomic) id delegate;
EnterYourNameController.m
-(void)button{
stringEntered=textField.text;
((Options *) (self.delegate)).string = stringEntered;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
Options *vc = [storyboard instantiateViewControllerWithIdentifier:@"Options"];
[self.navigationController pushViewController:vc animated:YES];
}
选项.h
@interface Options : UIViewController <MFMailComposeViewControllerDelegate> {
NSString *string;
}
@property (strong,nonatomic) NSString* string;
@end
选项.m
NSString *emailBody = [NSString stringWithFormat:@"%@",string];