ios - 为什么我的数据没有通过 View Controller 传递?

标签 ios objective-c string

我正在尝试将文本字段文本从一个 Controller 传递到另一个 Controller ,以便我可以通过电子邮件发送它。我正在遵循一个例子,但我一定遗漏了一些小细节。基本上,目标是将数据文本字段文本从 Enteryournamecontroller Controller 传递到选项 Controller 的 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];

最佳答案

-(void)按钮方法中,初始化Options Controller 并设置值。

-(void)button{

       stringEntered=textField.text;
       Options *optViewController = [[Options alloc] init];
       optViewController.string = stringEntered;
       //call your optViewController here
  }

关于ios - 为什么我的数据没有通过 View Controller 传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18487451/

相关文章:

java - 尝试快速使用 CMYK 值

ios - 目标 - C : UITableView Content Changing on Scroll

javascript - 通过查找关键字将 Javascript 字符串拆分为字符串数组

iphone - 如何公开类成员或如何实现对那些成员起作用的方法

ios - 如何在没有过滤器的情况下从设备中检索所有 CNContactStore

ios - Swift 5.3 未显示在 xcode 12 build设置中

objective-c - 在我可以使用我的方法本地 NSOpenSavePanelDelegate 之前,ARC 会杀死它。有解决办法吗?

ios - Sprite Kit 是否发布了 Unseen Sprites

java - 在java中读取XML标签

python - 捕获最多三位数的所有数字