大家好,我在视图之间传递值时遇到了很多麻烦,
我有一个带有 3 个文本框 FirstName LastName 电子邮件的 StartViewController 我想将它们的值传递给 ViewController 我尝试了一些不同的东西,但我所做的似乎没有任何工作我试过这个: http ://highscoreapps.blogspot.com/ 2012/05/passing-data-between-view-controllers.html http://www.theappcodeblog.com/2011/04/15/passing-data-between-views-tutorial-using-a-protocol-delegate-in -你的 iPhone 应用程序/
但我似乎无法得到任何工作。到目前为止,这是我的一些代码:
在 StartViewControler.h
@protocol DataPassingControllerDelegate <NSObject>
-(void)passDataMethod:(NSString *)TextFirstName Data2:(NSString *)TextLastName Data3:(NSString *)TextEmail;
@property(nonatomic,retain) IBOutlet UITextField *uTextFirstName;
@property(nonatomic,retain) IBOutlet UITextField *uTextLastName;
@property(nonatomic,retain) IBOutlet UITextField *uTextEmail;
@property (nonatomic, strong) NSString *sTextFirstName;
@property (nonatomic, strong) NSString *sTextLastName;
@property (nonatomic, strong) NSString *sTextEmail;
@property (nonatomic, unsafe_unretained) id<DataPassingControllerDelegate> delegate;
在 StartViewController.M
-(IBAction)ButtonTakeSurvey:(id)sender{
self.sTextFirstName = uTextFirstName.text;
self.sTextLastName = uTextLastName.text;
self.sTextEmail = uTextEmail.text;
[self.delegate passDataMethod:sTextFirstName Data2:sTextLastName Data3:sTextEmail];
ViewController *myView1 = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
[self.view addSubview:myView1.view];
}
在 ViewController.HI 中添加了 #import "StartViewController.h"
@interface ViewController : UIViewController <DataPassingControllerDelegate>
如何在 ViewController.m 上获取 firstName LastName 电子邮件我希望它填充我已加载的 3 个局部变量。
谢谢!