gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-30 19:52:07 24 4
gpt4 key购买 nike

我有一个类似 NSString *str = @"123" 的字符串。我想将这个字符串的数字填充到 UIPickerView 中。但是如何从这个字符串中获取数字?我添加了以下代码

- (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];
}

关于iphone - 如何从 NSString 中获取整数的数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12072473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com