Вопрос

I would like to know if it's possible (and how) when the keyboard appears in the DetailView, to disable any MasterView controls until it disappears. All of this happens in a split view based app of course.

---Update for Prince's solution---

MasterViewController.h

@property (strong, nonatomic) UIView *MasterView;

MasterViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    MasterView=self.view;

    self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
    self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
}

DetailViewController.m

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    ((MasterViewController *)self.parentViewController).MasterView.userInteractionEnabled=NO;

    return YES;
}

This code as is, crashes the app with an "Unknown Selector" error. How do i bind delegates; Don't know if that's the problem or not. Any help?

Это было полезно?

Решение 2

I found out a solution!

in MasterView viewDidLoad:

//---registers the notifications for keyboard---
    // to see if keyboard is shown / not shown
    [[NSNotificationCenter defaultCenter]
     addObserver: self
     selector:@selector(keyboardDidShow:)
     name:UIKeyboardDidShowNotification
     object:self.view.window];

    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(keyboardDidHide:)
     name:UIKeyboardDidHideNotification
     object:nil];

and then...:

//----------Handling Keyboard Appearence---
-(void) keyboardDidShow:(NSNotification *) notification {
    [self.tableView setUserInteractionEnabled:NO];
}

//---when the keyboard disappears---
-(void) keyboardDidHide:(NSNotification *) notification {
    [self.tableView setUserInteractionEnabled:YES];
}

//---before the View window disappear---
-(void) viewWillDisappear:(BOOL)animated {
    //---removes the notifications for keyboard---
    [[NSNotificationCenter defaultCenter]
     removeObserver: self
     name:UIKeyboardWillShowNotification
     object:nil];

    [[NSNotificationCenter defaultCenter]
     removeObserver:self
     name:UIKeyboardWillHideNotification
     object:nil];
}

Другие советы

Use UITextField's delegate and also bind delegates:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
   MasterView.userInteractionEnabled = NO;

   .......
   return YES;
} 

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
   MasterView.userInteractionEnabled = YES;
   [textField resignFirstResponder];
   return YES;
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top