简体   繁体   English

UITextField停止响应触摸

[英]UITextField Stops Responding To Touches

I have a storyboard with a UIView with two UITextFields within it. 我有一个带有UIView的情节提要,其中有两个UITextFields。 When I navigate back to the controller the UITextFields no longer respond to touch. 当我导航回控制器时,UITextFields不再响应触摸。 I am navigating to the controller like this 我正在导航到这样的控制器

UIViewController* controller = [self rootNavigationController].storyboard] 
instantiateViewControllerWithIdentifier:@"mycontroller"];

for some reason once I do this, they stop responding. 由于某种原因,一旦我这样做,他们就会停止响应。

As far as the controller is concerned, it only has a few IBOutlets 就控制器而言,它只有几个IBOutlets

myController.h myController.h

@interface myController : UIViewController

@property (nonatomic,weak) IBOutlet UIView *mainView;
@property (nonatomic,weak) IBOutlet UITextField *field1;
@property (nonatomic,weak) IBOutlet UITextField *field2;

@end

myController.m myController.m

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:(BOOL)animated];
    [self.field1 becomeFirstResponder];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.field2.layer.borderColor =[[UIColor colorWithRed:4.0/255.0
                                                           green:108.0/255.0
                                                            blue:187.0/255.0
                                                           alpha:1.0] CGColor];
    self.field2.layer.borderWidth = 1.0;

    self.field1.layer.borderColor =[[UIColor colorWithRed:4.0/255.0
                                                           green:108.0/255.0
                                                            blue:187.0/255.0
                                                           alpha:1.0] CGColor];
    self.field1.layer.borderWidth = 1.0;
}

I have the IBOutlets hooked up on the story board. 我已将IBOutlets连接到故事板上。

I've tried cliptobounds on the mainView. 我已经在mainView上尝试过cliptobounds了。 But it doesn't work. 但这是行不通的。

What you're doing with the following code: 以下代码在做什么:

UIViewController* controller = [self rootNavigationController].storyboard] 
instantiateViewControllerWithIdentifier:@"mycontroller"];

You're creating a new instance of mycontroller . 您正在创建mycontroller的新实例。 That's why, as you said: " once I do this, they stop responding." 正如您所说,这就是为什么:“一旦我这样做,他们就会停止回应。”

Therefore, the solution to your problem would be, not to create a new instance of the previous viewController , but to just navigate back. 因此,解决您的问题的方法将是,不创建先前viewController的新实例,而只是向后导航。 Here is what I mean: 这是我的意思:

Remove this: 删除此:

\n

 
 
 
  
  UIViewController* controller = [self rootNavigationController].storyboard] instantiateViewControllerWithIdentifier:@"mycontroller"];
 
  

And in place of that, insert the following: 并替换为以下内容:

[self.navigationController popViewControllerAnimated:YES];

Hope this helps!! 希望这可以帮助!! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM