zoukankan      html  css  js  c++  java
  • 如何编辑我的数组的for循环Reflrect呢? ()

    iphone objective-c

    我的数组的for循环目前导致同样的数字:0,1,2,3,4,5,6 .... 1000。 下面是代码:

    pickerArray = [[NSMutableArray alloc] initWithCapacity:700];
     for ( int i = 1 ; i <= 1000 ; i = i++)
      [pickerArray addObject:[NSString stringWithFormat:@"%i", i]]
    

    我想它代替,具有以下图案,0,2.5,5,7.5,10 CodeGo.net,12.5,15,17.5,20,等等。 而正是这样的代码:

    float weight = [[pickerArray objectAtIndex:row] intValue];
    label.text = [NSString stringWithFormat:@"%f lb", weight];

    1.
    pickerArray = [[NSMutableArray alloc] initWithCapacity:700];
    for ( float i = 0.0 ; i <= 1000.0 ; i = i + 2.5)
    {
     //[pickerArray addObject:[NSString stringWithFormat:@"%.1f", i]]
     [pickerArray addObject:[NSNumber numberWithFloat:i];
    }
    
    float weight = [[pickerArray objectAtIndex:row] floatValue];
    label.text = [NSString stringWithFormat:@"%.1f", weight];
    

    2. 您可以在回路中做到这一点:
    for ( float f = 0; f <= 1000; f = f + 2.5 )
     [pickerArray adObject:[NSString stringWithFormat:@"%.1f", f]];
    
    或者你可以在创建字符串时只需乘以:
     [pickerArray adObject:[NSString stringWithFormat:@"%.1f", 2.5*i]];
    
    另外,如果你把1000个对象中,为什么700的初始容量开始?而且你真的确定你要在这个数组中所有的字符串? 编辑:和看了你的编辑,你真的确定要这么做看似冗余的来回转换为字符串?好吧,如果你确定:
    float weight = [[pickerArray objectAtIndex:row] floatValue];
    

    3. 试试这样:
    pickerArray = [[NSMutableArray alloc] initWithCapacity:1001];
    for ( int i = 0 ; i <= 1000 ; ++i)
     [pickerArray addObject:[NSString stringWithFormat:@"%.1f", 2.5*i]]
     
  • 相关阅读:
    SQL函数union,union all整理
    Oracle中的having()函数
    SQL函数count(),sum()理解
    Office Online Server 和 SharePoint 2016配置时报错
    Manjaro 黑苹果网卡BCM4360折腾记
    Manjaro安装与基本配置
    在Arch Linux/Manjaro上安装KVM、QEMU和Virt Manager的方法
    Nginx 优化详解
    xargs 使用详解
    Centos7 搭建lnmp环境 (centos7+nginx+MySQL5.7.9+PHP7)
  • 原文地址:https://www.cnblogs.com/wsir/p/6773224.html
Copyright © 2011-2022 走看看