문제

I need to set an NSInteger to the number in a text field. And I've googled it and could not find any answer. Does anybody know how to do this

도움이 되었습니까?

해결책

NSInteger x = [textField.text integerValue];

다른 팁

John C. Daub answer is perfect. I would add this also:

NSInteger x = [[NSNumber numberWithInteger:[field.text integerValue]] integerValue];

The advantage of NSNumber is that if you want to pass this integer into dicitonary, NSNumber helps.

On the other hand a call to integerValue would be sufficient.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top