开发者

Validate UITextField

开发者 https://www.devze.com 2023-02-10 00:50 出处:网络
I have a UITextField in my app, created in IB. I need to validate the same. i.e. it should be a number between 2 and 20

I have a UITextField in my app, created in IB. I need to validate the same. i.e. it should be a number between 2 and 20

What is the best possible way of doing the validation; through code OR can this be completely controlled from the IB ?

Please 开发者_开发百科let me know the ways to validate the field.


You can't validate that from Interface Builder.

Try something like this. After textField initialization, put a Value Changed handler like this:

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

Then write a message like this:

- validateField:(id)sender
{
    // put validation code here
}
0

精彩评论

暂无评论...
验证码 换一张
取 消