我在viewcontrollerB中使用文本视图,同时在用户点击导航控制器的按钮时编辑textview,视图应弹出到viewcontrollerA
我的代码是
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
edit_TEXT = textField.text;
}
-(void) back;
{
employer_REG_NEW *empSIGHN_UPVC = [employer_REG_NEW alloc] ;
empSIGHN_UPVC.view_LINE = edit_TEXT;
}
我没有在viewcontrollerA中获取字符串
答案 0 :(得分:0)
1) @IBOutlet weak var txtName:UITextField! @IBOutlet weak var lblGetValue1:UILabel!
var str2 = String()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
self.lblGetValue1.text = str2
}
@IBAction func btnPassValueAction(_ sender: Any) {
let passData = storyboard?.instantiateViewController(withIdentifier: "SecondVC") as! SecondVC
// passData.delegate = self passData.str = txtName.text!
self.navigationController?.pushViewController(passData, animated: true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
2) @IBOutlet weak var txtPassValue:UITextField! @IBOutlet weak var lblGetValue:UILabel!
var str = String()
//var delegate : myProtocol?
override func viewDidLoad() {
super.viewDidLoad()
self.lblGetValue.text = str
}
@IBAction func btnSendDataAction(_ sender: Any) {
for viewController: UIViewController in (self.navigationController?.viewControllers)!{
if (viewController is ViewController){
let filterData: ViewController = (viewController as? ViewController)!
filterData.str2 = txtPassValue.text!
self.navigationController?.popToViewController(filterData, animated: true)
}
}
答案 1 :(得分:-1)
在viewcontrollerB.h中创建协议
@protocol testDelegate <NSObject>
-(void)sendText:(NSString *)strText;
@end
声明属性
@property (strong,nonatomic)id<testDelegate>delegate;
在viewcontrollerB.m中的从你传递文本到后面的viewcontrollerA写在下面
[self.delegate sendText:@"Hello"]
在viewcontrollerA中
添加Delegate方法 和
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
viewcontrollerB *obj = segue.destinationViewController;
obj.delegate = self;
}
并声明委托方法
你在哪里发送文字。
的完整详情