English 中文(简体)
UIText Field “数值改变”在外地更新后不发射
原标题:UITextField "value changed" not firing when field is updated

我有一个<代码>IBAction,我与Interface Buildinger的要素链接。 (关于“变值”活动)

我还有一份<代码>UISlider,在对文本的实地要素进行价值调整时,自动更新该文本。

当我接手时,文本领域确实在我调整斜体时得到更新,但“价值改变”事件在出现时不会火灾。 当我用手把案文放在现场时,价值变化的事件也不会发生火灾。 (在使用迪德编辑末端触发器时,确实造成火灾)。

我的问题是,如果对文本领域进行方案更新,以及用户调整其价值,那么我如何能够将价值改变为火焰。

最佳回答

根据Ronin的建议,使用<代码>UIText FieldDelegate,并采用以下方法:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
问题回答

Don t use UIControlEventValueChanged for UIText Field. 您想要的是UIControlEventEditingChanged

为了获得<条码>纸张缩略语(),我建议增加选任人,作为选号。

[textField addTarget:self action:@selector(textChanged:) forControlEvents:UIControlEventEditingChanged];

随着案文点值的改变,你将从<条码>上改动:遴选人。

-(void)textChanged:(UITextField *)textField
{
    NSLog(@"textfield data %@ ",textField.text);
}

当时,国际红十字与红新月联会派一名代表到案文领域,你指出(当你从以下代表方法中调回诺时,活动(变换)胜诉。 考虑在您从这一方法返回时援引活动听众。

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

虽然价值按方案分配,但在这种情况下,案文 由于实际案文,从来就不必打电话。 实地点吨数变化。 这一外部活动需要通过

比如,textfield.sendActions (for: editingChanged),这将对经修改的编辑活动和文本造成火灾 外地 即使在方案价值发生变化之后,也将叫DidChange。

?

在对提交的案文分配价值之后,textfield.text = “一些价值”

Swift 4:

class YourViewController: UIViewController {
    // MARK: Outlets
    @IBOutlet weak var titleTextField: UITextField!

    // MARK: View lifecycle
    override func viewDidLoad() {
        super.viewDidLoad()
        titleTextField.delegate = self
    }
}

// MARK: UITextFieldDelegate methods
extension YourViewController: UITextFieldDelegate {
    func textField(_ textField: UITextField,
                   shouldChangeCharactersIn range: NSRange,
                   replacementString string: String) -> Bool {
        print("changed")
        return true
    }
}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签