gpt4 book ai didi

ios - xcode textFieldDidFinishEditing 不工作

转载 作者:行者123 更新时间:2023-11-28 22:32:01 25 4
gpt4 key购买 nike

我今天真的很头疼,需要一些帮助/建议才能解决。

问题

代码中的所有内容都运行良好,但是我在让 textFieldDidFinishEditing 正确触发时遇到了很大的问题它没有被调用是出于什么原因(可能是因为我不明白)我有让 textFieldDidBeginEditing 正常工作并且我正在应用相同的逻辑,但它根本不起作用。

我做了一些事情,字段的 delegate 设置正确,知识库删除再次证明了这一点,文本字段变灰并且 nslog 输出正确(除了 did finish编辑)。

它应该做的是,当用户输入一个值然后离开文本字段 1 或 2 时,它会用值填充另一个字段,即 text1 = 2 当用户退出该字段时 textFieldDidFinishEditing触发然后运行代码以将文本字段 2 设置为 = 2。但它甚至不工作甚至没有被调用。我知道我可以从 IB 中设置它并结束编辑发送的事件但是 id 宁愿不使用它。

我尝试使用 textFieldDidEndEditing - 这确实有效,但是它会在我传递任何值之前释放响应程序等,我已经阅读了 UITextField 类的 apple 开发人员部分,并且相信我做的是正确的(显然不是,因为它不工作)所以我很茫然,任何帮助都会很感激

代码

下面是我的代码的副本

//
// ViewController.m
// didendediting
//
// Created by Developer on 16/06/2013.
// Copyright (c) 2013 Mr H. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

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

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}



//Checking for edit state on each of the text fields this works fine as does what is expected
- (void)textFieldDidBeginEditing:(UITextField *)textField

{

if (textField.tag == 0) //text 1 field
{
self.text1.backgroundColor = [UIColor lightGrayColor];
self.text2.backgroundColor = [UIColor whiteColor];
NSLog(@" Text 1 Became First Responder");
//self.blockWidth.text=self.blockLength.text;
}
else if (textField.tag == 1) //text 2 field
{
self.text2.backgroundColor = [UIColor lightGrayColor];
self.text1.backgroundColor = [UIColor whiteColor];
NSLog(@" Text 2 Became First Responder");
}
}

//use this to get rid of the KB when the user clicks anywhere on the screen - again this
//works fins as it removes the kb from screen
- (IBAction)hideKeyboard:(id)sender

{
[self.text1 resignFirstResponder];
[self.text2 resignFirstResponder];
NSLog(@"RESPONDER Released");
}

//This is the area that is not working
- (void)textFieldDidFinishEditing:(UITextField *)textField

{

if (textField.tag == 0) //text 1 field
{

NSLog(@"text 1 finished editing");
self.text1.text=self.text2.text;

}

else if (textField.tag == 1) //text 2 field
{

NSLog(@"text 2 finished editing");
self.text2.text=self.text1.text;
}

else
{
NSLog(@"something gone wrong");
}

}
@end

最佳答案

你有这些UITextField delegates :

– textFieldShouldBeginEditing:
– textFieldDidBeginEditing:
– textFieldShouldEndEditing:
– textFieldDidEndEditing:

而且我认为您正在寻找 – textFieldDidEndEditing:

关于ios - xcode textFieldDidFinishEditing 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17134791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com