按钮上的UITextField键盘关闭单击UIApplication方法

时间:2014-03-24 19:07:59

标签: objective-c uitextfield uisplitviewcontroller uiapplicationdelegate resignfirstresponder

我将从故事板转到xib中的UISplitViewController。我想注销我的故事板视图,这将带我到UISplitViewController。在storyboard控制器中,我有一个UITextField。我设置它以便在按下回车后它不会自动解除。但是,即使我切换到splitviewcontroller,它现在仍保持打开状态,我显然不想这样,因为我想退出。

退出按钮

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

调出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];

        }}

  }
委托中的

方法gotoSplitViewController:

-(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];



}

我的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];

我已尝试过resignFirstResponder,如果有不同的地方,包括添加

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

}

但是,它们都不起作用。如何在视图更改后让键盘消失?

1 个答案:

答案 0 :(得分:0)

我设置

self.chatBox.delegate=nil;

在我的方法中切换视图