2

I'm going from storyboard to UISplitViewController in a xib. I want to logout of my storyboard view, which will bring me to the UISplitViewController. In the storyboard controller, I have a UITextField. I set it so that it doesn't dismiss itself after I press enter. However, it now stays open even when I switch to the splitviewcontroller, which I obviously don't want because i want to logout.

Logout Button

  UIBarButtonItem *logoutButton = [[UIBarButtonItem alloc] initWithTitle:@"Log Out" style:UIBarButtonItemStylePlain target:self action:@selector(confirmLogout)];

Method to bring up UISplitViewCOntroller

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{

    if (alertView.tag==TAG_DEV){


        if (buttonIndex) {


            [[[UIApplication sharedApplication] delegate] performSelector:@selector(gotoSplitViewController)];


        } else {



            [self.navigationController popViewControllerAnimated:YES];

        }}

  }

method gotoSplitViewController in the delegate:

-(void)gotoSplitViewController{




    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    ListViewController *listVC = [[ListViewController alloc] initWithStyle:UITableViewStylePlain];
    UINavigationController *listNC = [[UINavigationController alloc] initWithRootViewController:listVC];

    AssignedViewController *assignedVC = [[AssignedViewController alloc] initWithNibName:@"AssignedViewController" bundle:nil];
    UINavigationController *assignedNC = [[UINavigationController alloc] initWithRootViewController:assignedVC];

    //assign the views to the new nav view controllers
    splitViewController = [[UISplitViewController alloc] init];
    splitViewController.delegate = assignedVC;
    splitViewController.viewControllers = @[listNC, assignedNC];

    listVC.detailViewController = assignedVC;


    [[self window] setRootViewController:splitViewController];

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];



}

my UITextField

self.textBox = [[UITextField alloc] initWithFrame: CGRectMake(10, 660, 750, 90)];
    self.textBox.backgroundColor = [UIColor colorWithRed:(209/255.0) green:(236/255.0) blue:(232/255.0) alpha:1];
    self.textBox.returnKeyType = UIReturnKeySend;
    self.textBox.delegate = self;
    [self.view addSubview:self.textBox];

I've tried the resignFirstResponder if various places, including adding

- (void)viewWillDisappear:(BOOL)animated
{
    [self.textBox resignFirstResponder];

}

However, none of them work. How do I get the keyboard to disappear after the views change?

user3325170
  • 133
  • 10
  • One thing you could try, if you haven't done so already is you could resignFirstResponder in confirmLogout. Another thing I can think of is that perhaps your textBox is no longer the first responder when you are calling it in viewWillDisappear. So you can force it to becomeFirstResponder since the keyboard is already visible and in the next line just resignFirstResponder. – nstein Mar 24 '14 at 19:25
  • Hi @nstein! Thank you for your help. I did try it in confirmLogout, but still didn't work :( But I didn't consider the other solution, that it wasn't a firstresponder. I will try that and let you know how it goes – user3325170 Mar 25 '14 at 15:48
  • hmm I still can't get it to work. Do you think it has anything to do with the self.chatBox.delegate = self; line? – user3325170 Mar 25 '14 at 16:16
  • Ok I found a behavior regarding the self.chatbox.delegate.self. When I removed that line, it would disappear when I changed views, so that's great. However, now the uitextview associated with the textfield won't receive the messages so that won't work. But I guess I have to undelegate ... do you ahve any ideas as to how this would work? – user3325170 Mar 25 '14 at 16:26
  • Just answered my own question i posed, i set it to self.chatbox.delegate=nil; – user3325170 Mar 25 '14 at 16:28

1 Answers1

0

I set

self.chatBox.delegate=nil;

in my methods to switch views

manuell
  • 7,528
  • 5
  • 31
  • 58
user3325170
  • 133
  • 10