Ios UITextField不';我的第二个视图控制器不能工作
我有个大问题。我在iOS中创建了一个新功能,我正在尝试这样做: 我有两个Ios UITextField不';我的第二个视图控制器不能工作,ios,iphone,objective-c,uitextfield,Ios,Iphone,Objective C,Uitextfield,我有个大问题。我在iOS中创建了一个新功能,我正在尝试这样做: 我有两个视图控制器。第一个视图有一个按钮,如果按下该按钮,控件将转到第二个视图控制器 这是可行的,但问题是当我尝试在第二个视图控制器中获取数据时。UITextfield不起作用 我正在尝试显示我在标签的文本字段中插入的内容。但是TEXTFIELD不起作用:( 我成功地将IBOutlets放入XIB中,并将按钮与其IBAction连接起来 这是我的代码: ViewController.h #import <UIKit/U
视图控制器
。第一个视图有一个按钮,如果按下该按钮,控件将转到第二个视图控制器
这是可行的,但问题是当我尝试在第二个视图控制器中获取数据时。UITextfield
不起作用
我正在尝试显示我在标签的文本字段中插入的内容。但是TEXTFIELD不起作用:(
我成功地将IBOutlets放入XIB中,并将按钮与其IBAction连接起来
这是我的代码:
ViewController.h
#import <UIKit/UIKit.h>
#import "SecondViewController.h"
@class SecondViewController;
@interface ViewController : UIViewController
@property (strong, nonatomic) SecondViewController *secondViewController;
-(IBAction)buttonClicked:(id)sender;
@end
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController {
IBOutlet UITextField *textField;
UIButton *obtener;
IBOutlet UILabel *label;
}
@property (nonatomic, retain) IBOutlet UITextField *textField;
@property (nonatomic, retain) IBOutlet UIButton *obtener;
@property (nonatomic, retain) IBOutlet UILabel *label;
-(IBAction)obtenerClicked:(id)sender;
@end
SecondViewController.h
#import <UIKit/UIKit.h>
#import "SecondViewController.h"
@class SecondViewController;
@interface ViewController : UIViewController
@property (strong, nonatomic) SecondViewController *secondViewController;
-(IBAction)buttonClicked:(id)sender;
@end
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController {
IBOutlet UITextField *textField;
UIButton *obtener;
IBOutlet UILabel *label;
}
@property (nonatomic, retain) IBOutlet UITextField *textField;
@property (nonatomic, retain) IBOutlet UIButton *obtener;
@property (nonatomic, retain) IBOutlet UILabel *label;
-(IBAction)obtenerClicked:(id)sender;
@end
在SecondViewController.h中,添加以下属性:
@property(nonatomic, readwrite) NSString* myString;
现在在firstViewController的onClick方法中,添加以下行
-(IBAction)buttonClicked:(id)sender {
//....... Previous code....
self.secondViewController.myString= @"String to be sent";
}
这将为您传递字符串
如果要在文本字段中传递字符串,请使用以下命令:
-(IBAction)buttonClicked:(id)sender {
//....... Previous code....
self.secondViewController.textField.text= @"String to be sent";
}
希望它能很好地满足您的要求
更新:执行以下操作以获得预期结果:
1.将第二个ViewController设置为textView代理 在第二个ViewController.h中 将
@interface SecondViewController:UIViewController
替换为@interface SecondViewController:UIViewController
如果不起作用,请告诉我。定义“不起作用”。您的意思是标签中没有设置文本值??我写了“某物”在textfield中。然后我按下按钮,标签继续为空。因此,程序不工作:/Hi friend,感谢您的回答。但这不是我的问题。我不想在ViewController之间发送数据。我想在第二个view controller中设置textfield,并使用iAction设置标签。您的解决方案是将数据发送到textfield,我想让用户把自己放进去。@Eladar你在点击文本字段时会得到一个键盘吗?我在使用模拟器的键盘,我也试过使用我的真实键盘,但同样,问题仍然存在。@Eladar..所以,当你在键盘上打字时,你看到文本字段中出现一些文本吗?是的,但当我按下按钮时,标签不与文本一起设置。