相关疑难解决方法(0)

如何识别哪个文本字段当前是第一响应者

如果屏幕上有多个文本字段,并且在点击它们时弹出键盘,如果您想以编程方式隐藏键盘或辞职第一响应者,但您不知道发送resignFirstResponder消息的文本字段,该怎么办?至?有没有办法确定哪个对象/ textField应该收到此消息?

iphone objective-c uikit ipad ios

5
推荐指数
2
解决办法
6243
查看次数

是否可以将文本字段与键盘关联?

在我的视图控制器中,我订阅了UIKeyboardWillShowNotification

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWillShow:)
                                             name:UIKeyboardWillShowNotification
                                           object:nil];
Run Code Online (Sandbox Code Playgroud)

因此,在我的keyboardWillShow:方法中,我可以从通知中检索有关键盘的一些信息。但是我想要获得的是对实际文本字段的引用,从而使键盘启动。我在Google中找不到该怎么做的方法,我怀疑这可能是不可能的,但有人可能知道。如果确实不可能,那么我想知道是否有可能使之相反-通过引用文本字段来获取有关键盘的信息。谢谢

cocoa-touch objective-c uitextfield uikit ios

5
推荐指数
2
解决办法
2332
查看次数

在UIAlertView中关闭UITextField的键盘

我有一个自定义的UIAlertView.我在该AlertView中有一个UITextField,它一出现就成为firstResponder.现在,当用户触摸AlertView中的其他位置时,我需要关闭该UITextField的键盘.我已经接触过此次活动.

一切都到位并且工作正常,除非我在UITextField上调用resignFirstResponder,它从第一个响应者辞职但键盘没有被解雇.有没有办法解雇那个键盘.

我一直在寻找解决方案,并在这里发现了类似的帖子,没有答案

如果有人能找到出路请告诉我.我甚至尝试了以下方式,但它不起作用

UIWindow* tempWindow;

    // Because we cant get access to the UIKeyboard throught the SDK we will just use UIView. 
    // UIKeyboard is a subclass of UIView anyways
    UIView* keyboard;

    // Check each window in our application
    for(int c = 0; c < [[[UIApplication sharedApplication] windows] count]; c ++)
    {
        // Get a reference of the current window
        tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:c];
        for(int i = 0; i < [tempWindow.subviews count]; i++)
        {
            // …
Run Code Online (Sandbox Code Playgroud)

iphone iphone-softkeyboard

4
推荐指数
1
解决办法
4865
查看次数

如何从inputAccessoryView按钮单击获取UITextField

我有一个动态的数字UITextFields都有一个inputAccessoryView.它由UIToolbar一个按钮组成.按下此按钮时,它会调用一个方法,但是,在此方法中,我需要能够访问底层UITextField.

请问有人可以告诉我这是怎么回事吗?

// Create the toolbar controls
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(navigationBarDoneButtonPressed:)];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

// Setup the toolbar
navigationToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(10.0, 0.0, 310.0, 40.0)];
[navigationToolbar setItems:@[flexibleSpace, doneButton]];

// In a UITableView I create a number of cells which contain UITextFields....

// This is the method that gets called when a user presses the done button
- (void)navigationBarDoneButtonPressed:(id)sender
{
    NSLog(@"Based on …
Run Code Online (Sandbox Code Playgroud)

objective-c uitextfield uitoolbar ios

4
推荐指数
1
解决办法
3641
查看次数

一种隐藏键盘的实用方法

在我的项目中,我有几个页面,包含许多UITextField-s.所以我认为最好创建一个名为hideKeyboard的实用程序方法,它在任何情况下都可以工作.这是我的解决方案,但实际上这段代码中的某些东西感觉不对.有没有更好的解决方案呢?

+(void) hideKeyBoard {
    UITextField* t = [[UITextField alloc] initWithFrame:CGRectNull];
    [[UIApplication sharedApplication].keyWindow addSubview:t];
    [t becomeFirstResponder];
    [t resignFirstResponder];
    [t removeFromSuperview];
}
Run Code Online (Sandbox Code Playgroud)

iphone keyboard objective-c ios

3
推荐指数
1
解决办法
1859
查看次数

从tableviewcell内的textfield中解除iPad上的键盘

我的iOS键盘有问题.我在UITableViewCell中有一个UITextField.当在同一个TableView中点击另一个TableViewCell时,我想在显示UIPopoverController之前解除键盘.所有这些都显示在表单中.

这是视图层次结构:

  • 根视图控制器
    • UINavigationController,显示为 UIModalPresentationFormSheet
      • 表视图控制器
        • 表格查看单元格1
          • 文本域
        • 表格查看单元格2
          • 点击时:UIPopoverController包含一个UIDatePicker

在此图中,我想tableView:didSelectRowAtIndexPath:在显示之前添加代码以关闭键盘UIPopoverController.这在iPhone上不是问题,因为我使用全屏模态视图控制器而不是弹出控制器.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // nameTextField is the text field in Table View Cell 1
    [nameTextField resignFirstResponder];

    UITextField *tempTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 100, 10)];
    [self.view addSubview:tempTextField];
    [self.view setNeedsDisplay];
    tempTextField.enabled = NO;
    [tempTextField becomeFirstResponder];
    [tempTextField resignFirstResponder];
    [tempTextField removeFromSuperview];

    [self.view endEditing:YES];

    KDDatePickerViewController *dpvc = [[KDDatePickerViewController alloc] init];
    popoverController = [[UIPopoverController alloc] initWithContentViewController:dpvc];
    [popoverController presentPopoverFromRect:[self.tableView cellForRowAtIndexPath:indexPath].frame
                                       inView:self.view
                     permittedArrowDirections:UIPopoverArrowDirectionAny
                                     animated:YES];
} …
Run Code Online (Sandbox Code Playgroud)

keyboard uitableview uipopovercontroller ios

1
推荐指数
1
解决办法
1453
查看次数

键盘出现时如何移动视图

我有多个UITextFields,我需要在键盘出现时向上移动视图.但我只需要3个底部字段,并且不希望移动顶部其他字段的视图.我使用这个代码,但是当用户点击每个字段时它的移动视图,而我只需要在用户点击2个底部字段时移动视图

- (void)viewWillAppear:(BOOL)animated {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}

- (void)viewWillDisappear:(BOOL)animated {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

#pragma mark - keyboard movements
- (void)keyboardWillShow:(NSNotification *)notification
{
    [UIView animateWithDuration:0.3 animations:^{
        CGRect f = self.view.frame;
        f.origin.y = -115.0f;  //set the -35.0f to your required value
        self.view.frame = f;
    }];
}

-(void)keyboardWillHide:(NSNotification *)notification
{
    [UIView animateWithDuration:0.3 animations:^{
        CGRect f = self.view.frame;
        f.origin.y = 0.0f;
        self.view.frame = f; …
Run Code Online (Sandbox Code Playgroud)

uitextfield ios

0
推荐指数
1
解决办法
231
查看次数