0

我想知道当键盘出现在 DetailView 中时是否有可能(以及如何)禁用任何 MasterView 控件,直到它消失。当然,所有这些都发生在基于拆分视图的应用程序中。

---Prince解决方案的更新---

主视图控制器.h

@property (strong, nonatomic) UIView *MasterView;

主视图控制器.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];
}

细节视图控制器.m

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

    return YES;
}

此代码原样使应用程序崩溃,并出现“未知选择器”错误。我如何绑定代表;不知道是不是这个问题。有什么帮助吗?

4

2 回答 2

0

使用 UITextField 的委托并绑定委托:

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

   .......
   return YES;
} 

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
   MasterView.userInteractionEnabled = YES;
   [textField resignFirstResponder];
   return YES;
}
于 2012-09-19T12:16:31.940 回答
0

我找到了解决方案!

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

进而...:

//----------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];
}
于 2012-10-09T19:58:03.407 回答