为什么我的数据没有从故事板传递到 Xcode objective c 中的 xib 文件?
Why is my data not being passed from storyboard to xib file in Xcode objective c?
我已经创建了一个故事板(ViewController)和一个 xib 文件(TargetVC)。我的意见很好。但是数据没有从一个 View controller 传递到 target view controller 。这是我的代码
Viewcontroller.h
#import <UIKit/UIKit.h>
#import "TargetVC.h"
@interface ViewController : UIViewController
{
TargetVC *target ;
}
@property (retain , nonatomic) IBOutlet UITextField *InputData;
- (IBAction)SendData:(id)sender;
@end
viewcontroller.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize InputData ;
- (IBAction)SendData:(id)sender {
target = [[TargetVC alloc]initWithNibName:@"TargetVC" bundle:nil];
target.userText = InputData ;
[self.view addSubview:target.view];
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
TargetVC.h
#import <UIKit/UIKit.h>
@interface TargetVC : UIViewController
{
UITextField *userText;
}
@property (retain , nonatomic) IBOutlet UILabel *ResultLabel;
@property (retain , nonatomic)UITextField *userText;
@end
TargetVC.m
#import "TargetVC.h"
@interface TargetVC ()
@end
@implementation TargetVC
@synthesize ResultLabel , userText;
- (void)viewDidLoad {
userText.text = ResultLabel.text ;
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
在您的代码中,ViewController
创建 TargetVC
,然后设置 TargetVC
的 userText
值。然后,您将 userText.txt
值重置为 ResultLabel.text
的值,但是您没有显示 ResultLabel.text
在哪里设置了它的值。
你可以改变这个
- (void)viewDidLoad {
userText.text = ResultLabel.text ;
[super viewDidLoad];
}
至此
- (void)viewDidLoad {
[super viewDidLoad];
ResultLabel.text = userText.text;
}
如果您尝试设置 ResultLabel.text
的值
或者,如果您尝试设置 ViewController
class 的值 UITextField
,那么您应该将 ViewController
设置为 TargetVC
的委托,并且以这种方式传递数据。
如果您正在尝试做其他事情,请更新您的问题并加以说明,我会 update/delete 我的回复。
我已经创建了一个故事板(ViewController)和一个 xib 文件(TargetVC)。我的意见很好。但是数据没有从一个 View controller 传递到 target view controller 。这是我的代码
Viewcontroller.h
#import <UIKit/UIKit.h>
#import "TargetVC.h"
@interface ViewController : UIViewController
{
TargetVC *target ;
}
@property (retain , nonatomic) IBOutlet UITextField *InputData;
- (IBAction)SendData:(id)sender;
@end
viewcontroller.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize InputData ;
- (IBAction)SendData:(id)sender {
target = [[TargetVC alloc]initWithNibName:@"TargetVC" bundle:nil];
target.userText = InputData ;
[self.view addSubview:target.view];
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
TargetVC.h
#import <UIKit/UIKit.h>
@interface TargetVC : UIViewController
{
UITextField *userText;
}
@property (retain , nonatomic) IBOutlet UILabel *ResultLabel;
@property (retain , nonatomic)UITextField *userText;
@end
TargetVC.m
#import "TargetVC.h"
@interface TargetVC ()
@end
@implementation TargetVC
@synthesize ResultLabel , userText;
- (void)viewDidLoad {
userText.text = ResultLabel.text ;
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
在您的代码中,ViewController
创建 TargetVC
,然后设置 TargetVC
的 userText
值。然后,您将 userText.txt
值重置为 ResultLabel.text
的值,但是您没有显示 ResultLabel.text
在哪里设置了它的值。
你可以改变这个
- (void)viewDidLoad {
userText.text = ResultLabel.text ;
[super viewDidLoad];
}
至此
- (void)viewDidLoad {
[super viewDidLoad];
ResultLabel.text = userText.text;
}
如果您尝试设置 ResultLabel.text
或者,如果您尝试设置 ViewController
class 的值 UITextField
,那么您应该将 ViewController
设置为 TargetVC
的委托,并且以这种方式传递数据。
如果您正在尝试做其他事情,请更新您的问题并加以说明,我会 update/delete 我的回复。