热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用整数值实例化NSArray-instantiateanNSArraywithintegersvalue

IhaveaPickerViewandIwanttoinitializeitwithintegervalues.ForexamplePickerViewwithall

I have a PickerView and I want to initialize it with integer values. For example PickerView with all integers lower than 10.

我有一个PickerView,我想用整数值初始化它。例如PickerView,所有整数都小于10。

Thank you

4 个解决方案

#1


NSArray *array =[NSArray arrayWithObjects:@1,@2,@3,@4,@5,@6,@7,@8,@9,nil];

#2


NSMutableArray *yourArray = [[NSMutableArray alloc] init];
    for (int i = 0; i <10; i++) {
        [yourArray addObject:[NSNumber numberWithInt:i]];
    }

#3


NSInteger min = 1;
NSInteger max = 10;
NSInteger step = 1;

NSMutableArray *optiOns= [NSMutableArray new];

for (NSInteger index = 0; index 

An alternate approach:

另一种方法:

NSInteger from = 1;
NSInteger size = 10;
NSInteger step = 1;

NSMutableArray *optiOns= [NSMutableArray new];

for (NSInteger index = 0; index 

Both of the above print the following:

以上两者都打印如下:

( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 )

(1,2,3,4,5,6,7,8,9,10)

#4


int yourInt = 5;
[myMutableArray addObject:[NSNumber numberWithInt:yourInt]]; have look on this 

It will just sample code to add the int value to the array nothing else

它只是示例代码将int值添加到数组中


推荐阅读
author-avatar
手机用户2502859861
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有