Iphone UITextField 仅整数 [英] Iphone UITextField only integer
本文介绍了Iphone UITextField 仅整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 IB 中有一个 UITextField,我想检查用户是否只输入数字(无字符)并获取整数值.
I have a UITextField in my IB and I want to check out if the user entered only numbers (no char)and get the integer value.
我像这样得到 UITextField 的整数值:
I get the integer value of the UITextField like that :
int integer = [myUITexrtField.text intValue];
当我输入一个字符 ( , ; . ) 时,它返回 0,我不知道如何检测它不仅仅是数字.
When I put a character ( , ; . ) it return me 0 and I don't know how to detect that it is not only numbers.
我该怎么办?
推荐答案
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric#Objective-C
或者您可以确保当焦点位于该字段时仅显示数字键盘
Or you could ensure that only the numeric keyboard appears when the focus comes on the field
这篇关于Iphone UITextField 仅整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文