gpt4 book ai didi

iphone - textFieldDidBeginEditing - 不工作

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

我的头文件

MyClass.h
@interface MyClass : UIViewController<UITextFieldDelegate>
{
}
@property (retain, nonatomic) IBOutlet UITextField *customValue;

MyClass.m

- (void)viewDidLoad
{
customValue.delegate=self;
}
- (void)textFieldDidBeginEditing:(UITextField *)customValue
{
NSLog(@"custom tips value %@",customValue.text);
}

我的 NSLog 正在打印消息,但是 customValue.text 没有显示,而是显示为 null。

编辑 1我需要在用户输入值时获取在文本文件中输入的值

最佳答案

textFieldDidBeginEditing 顾名思义,当您开始在 textField 上进行编辑时,它将起作用。

为了完成您的要求,您需要使用 shouldChangeCharactersInRange 委托(delegate)方法。

- (BOOL)textField:(UITextField *)e shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString *substring = textField.text;
substring = [substring stringByAppendingString:string];
NSLog(@"Text : %@",substring);
return YES;
}

textFieldDidBeginEditing:

Tells the delegate that editing began for the specified text field.

- (void)textFieldDidBeginEditing:(UITextField *)textField Parameters

textField

The text field for which an editing session began.

Discussion

This method notifies the delegate that the specified text field just became the first responder. You can use this method to update your delegate’s state information. For example, you might use this method to show overlay views that should be visible while editing.

Implementation of this method by the delegate is optional. Availability

Available in iOS 2.0 and later.

Declared In UITextField.h

textField:shouldChangeCharactersInRange:replacementString:

Asks the delegate if the specified text should be changed.

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

Parameters

textField

The text field containing the text.

range

The range of characters to be replaced 

string

The replacement string. 

Return Value

YES if the specified text range should be replaced; otherwise, NO to keep the old text. Discussion

The text field calls this method whenever the user types a new character in the text field or deletes an existing character. Availability

Available in iOS 2.0 and later.

Declared In UITextField.h

查看更多UITextFieldDelegate

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

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