标签: resignfirstresponder

UITableView reloadData自动调用resignFirstResponder

我有这个UITableView与自定义单元格,只能获得预定义的值,因此我使用UIPickerView作为他们的inputView.在我编辑一个字段并需要显示其更新值之前,一切都很快乐.

为了使事情更清晰,更容易维护,我将委托和数据源作为单独的类,并使用通知使它们与tableView交互.因此,在从UIPickerView中选择一个值之后,tableView的数据源会得到通知,然后通知主ViewController,它包含对tableView的引用.从那里我打电话

[_tableView reloadData];
Run Code Online (Sandbox Code Playgroud)

一切似乎都有效,除了UIPickerView消失了,我认为因为细胞被重新生成,某些地方调用了一些resignFirstResponder,或类似的东西.是否有任何其他方法可以使tableView更新其值而无需在某个地方实现自定义方法,这会非常难看?

uitableview ios resignfirstresponder

42
推荐指数
5
解决办法
3万
查看次数

UITextField的键盘不会被忽略.不完全是

我在模态表单(iPad)中有一个表视图,其中一个单元格包含一个UITextField.我的视图控制器拥有对文本字段的引用,也是其委托.

当文本字段命中Return时,我告诉它在-resignFirstResponder里面-textFieldShouldReturn:.在另一种情况下,我想强制它结束编辑,所以我告诉整个表视图-endEditing:YES.然后我释放我对文本字段的本地引用,并重新加载行以用其他东西替换它.

在任何一种情况下,键盘都不会消失.我不知道出了什么问题,我不确定如何进一步调试.我从来没有遇到任何其他文本编辑的粘性键盘问题 - 第一个响应者辞职总是表现得如预期的那样.

有什么想法吗?谢谢.

uitableview uitextfield ipad ios resignfirstresponder

15
推荐指数
2
解决办法
5865
查看次数

为什么UITextField在resignFirstResponder上设置动画?

从iOS 8开始,表单中的UITextField表现得非常奇怪.如果我单击另一个文本字段或按键盘上的Tab键,输入的文本将向上设置动画,然后快速重新显示.每次视图加载后都会发生这种情况,之后不时发生.

它看起来像这样:

动画

我的代码看起来像这样:

#pragma mark - <UITextFieldDelegate>

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField == self.passwordTextField) {
        [self loginButtonClicked:nil];
    } else if (textField == self.emailTextField) {
        [self.passwordTextField becomeFirstResponder];
    }

    return YES;
}
Run Code Online (Sandbox Code Playgroud)

编辑:

看起来这个问题是由我的键盘监听器引起的:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];


- (void)keyboardWillHide:(NSNotification *)sender
{
    self.loginBoxBottomLayoutConstraint.constant = 0;

    [self.view layoutIfNeeded];
}

- (void)keyboardWillShow:(NSNotification *)sender
{
    CGRect frame = [sender.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGRect newFrame = [self.view convertRect:frame fromView:[[UIApplication sharedApplication] delegate].window];
    self.loginBoxBottomLayoutConstraint.constant = CGRectGetHeight(newFrame);

    [self.view layoutIfNeeded];
}
Run Code Online (Sandbox Code Playgroud)

animation objective-c uitextfield ios resignfirstresponder

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

为多个UITextField重新启动First Responder

有一个应用程序,我UITextFields动态生成多个.我想在UITextFields没有选择的情况下辞职第一响应者(在外面触摸UITextField).我怎么知道UITextField我必须辞职的第一响应者?请指出除"标签"概念之外的任何其他方式,因为我已尝试过.请建议正确的方向.提前致谢.

iphone uitextfield ios resignfirstresponder

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

在eventFirstResponder或resignFirstResponder的情况下,将对象保持在键盘顶部?

我目前在键盘上有一个UITextField.点击它时,它应该粘在键盘顶部并平稳向上移动.我不知道键盘的确切持续时间和动画类型,所以它真的很颠簸.这就是我所拥有的:

[theTextView resignFirstResponder];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.25];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
// Frame changes go here (move down 216px)
[UIView commitAnimations];

[theTextView becomeFirstResponder];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.25];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
// Frame changes go here (move up 216px)
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)

如果有人之前做过这样的事情,我想知道你用来使动画变得平滑的设置,并让它看起来像是"卡在"键盘的顶部.

iphone objective-c uitextfield becomefirstresponder resignfirstresponder

13
推荐指数
2
解决办法
7672
查看次数

iPhone:在应用程序上隐藏键盘输入背景或视图已消失

我有一个UISearchBar,点击后会显示键盘.但是,如果用户在显示键盘时按下主页按钮然后返回应用程序,则键盘仍然可见.当应用程序关闭/进入后台时,如何隐藏键盘?

我在viewDidDisappear中尝试了以下内容:

[eventSearchBar resignFirstResponder];

[eventSearchBar endEditing:YES];
Run Code Online (Sandbox Code Playgroud)

我也在appDidEnterBackground中的委托中尝试过这个:

[self.rootController.navigationController.view endEditing:YES];
Run Code Online (Sandbox Code Playgroud)

这些都没有奏效.

iphone uisearchbar ios resignfirstresponder

13
推荐指数
2
解决办法
8165
查看次数

IPad在不知道哪个Textfield打开它的情况下关闭键盘

有没有办法做一般resignFirstResponder隐藏键盘,无论textfield/view/etc调用它?

原因是我的视图中有很多文本字段,并且不希望resignFirstResponder所有文本字段都隐藏键盘.只想要一个将军

[self resignFirstResponder].

有任何想法吗?

提前致谢

iphone keyboard objective-c ipad resignfirstresponder

12
推荐指数
3
解决办法
3470
查看次数

ResignFirstResponder无法正常工作

-(IBAction)settings:(id)sender
{
    [mileagerate resignFirstResponder];

    [mainView bringSubviewToFront:mileageView];
    mainView.hidden=TRUE;

    [UIView beginAnimations:@"Settings" context:nil];
    [UIView setAnimationDuration:1.0];
    [mainView setFrame:CGRectMake(0, 0, 320, 460)];
    [UIView commitAnimations];
    mileagerate.text = [[NSUserDefaults standardUserDefaults] valueForKey:@"savedstring"];

    mileageView.hidden=FALSE;
}
Run Code Online (Sandbox Code Playgroud)

我在我的应用程序中的各个地方使用了resign第一响应者.但是当我单独点击此按钮时,键盘不会消失.如果我单击键盘上的返回键,则输入的值将消失.

iphone objective-c resignfirstresponder

9
推荐指数
2
解决办法
1万
查看次数

IOS 7 UITextField resignFirstResponder BAD

我在使用UItextField时遇到了崩溃,在我的customCell中,当我resignFirstResponder文本字段时,但它不再可见(表格视图滚出窗口).我仍然可以找到文本字段,指针继续可访问,它不为空,崩溃只发生在IOS7上,在IOS6上我没有这个问题.下面是一些代码:

textField是一个全局变量.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString * CellIdentifier = [NSString stringWithFormat:@"Cell%d",indexPath.row];

    TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[TableCell alloc] init];

        if(indexPath.row == 0)
        {
            [textField setFrame:CGRectMake(15, 5, cell.frame.size.width-60, cell.frame.size.height)];
            textField.textAlignment = NSTextAlignmentLeft;
            [textField setBorderStyle:UITextBorderStyleNone];
            textField.textColor = [UIColor blackColor];
            textField.tag = indexPath.row;
            textField.delegate = self;
            textField.secureTextEntry = YES;
            [textField setFont:[UIFont fontWithName:@"Arial-BoldMT" size:15]];
            textField.textColor = [UIColor whiteColor];
            textField.returnKeyType = UIReturnKeyDone;
            [textField setAdjustsFontSizeToFitWidth:YES];
            textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
            textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Senha" …
Run Code Online (Sandbox Code Playgroud)

objective-c uitextfield ios resignfirstresponder ios7

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

SwiftUI 在点击 segmentedControl 时关闭键盘

我在 SwiftUI 中有一个 TextField,它需要使用不同的键盘,具体取决于由 SegementedControl() 选择器确定的 @State 变量的值。

当用户点击不同的段时,如何关闭键盘(如发送 endEditing 事件)?我需要这样做是因为我想更改键盘类型,如果 textField 是响应者,则键盘不会改变。

我有这个扩展:

extension UIApplication {
    func endEditing() {
        sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
    }
}
Run Code Online (Sandbox Code Playgroud)

我可以做类似的事情

UIApplication.shared.endEditing()
Run Code Online (Sandbox Code Playgroud)

但是当用户点击不同的段时,我不知道在哪里或如何调用它。

我试过在 Picker 上放置一个 tapGesture 并且键盘确实关闭了,但是点击不会传递到选择器,所以它不会改变。

代码片段在这里:

@State private var type:String = "name"
Run Code Online (Sandbox Code Playgroud)

. . .

Form {
    Section(header: Text("Search Type")) {
        Picker("", selection: $type) {
            Text("By Name").tag("name")
            Text("By AppId").tag("id")
        }.pickerStyle(SegmentedPickerStyle())
    }

    Section(header: Text("Enter search value")) {
        TextField(self.searchPlaceHolder, text: $searchValue)
            .keyboardType(self.type == "name" ? UIKeyboardType.alphabet : UIKeyboardType.numberPad)
    }
}
Run Code Online (Sandbox Code Playgroud)

ios resignfirstresponder swiftui

9
推荐指数
2
解决办法
2703
查看次数