NSTextField to uint16_t
I have a text field in my iPhone app and I want to convert what the user enters and convert that to a uint16_t
. How can I do that?
The text box will only be their for entering numb开发者_如何学运维ers.
This should work:
uint16_t integer = (uint16_t)[myTextField.text integerValue];
This will take the text field's text, convert it to an integer and cast it to a uint16_t
. Note that it will not work if the user enters a value bigger than 65,535 (or less than 0 for that matter).
精彩评论