iphone – 如何从NSString获取整数的数字?

前端之家收集整理的这篇文章主要介绍了iphone – 如何从NSString获取整数的数字?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个像NSString * str = @“123”这样的字符串.我想把这个字符串的数字填充到UIPickerView.But如何从这个字符串中获取数字?我添加了以下代码

- (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component 
{
 int number = [str intValue];
 if(component == 0)
 {

 }
 else if(component == 1)
 {

 }
 else 
 {

 }
}

解决方法

请看这个..

NSMutableArray *arrNumbers = [[NSMutableArray] alloc] initWithCapacity:[YOURSTRING length]];

for (i=0;i<[YOURSTRING length];i++) 
{
  unichaar ch = [YOURSTRING characterAtIndex:i];
  NSLog(@"Processing charachter %c",ch);
  // If you really want
  [arrNumbers addObject:(id)ch];
}

猜你在找的Xcode相关文章