ios 如何替换掉ios nsarray转json中指定的元素

查看:8262|回复:2
初级工程师
如何从NSArray数组中移除项目呢?
助理工程师
nsarray是不能删除数据的,因为nsarray不可以修改
你要用nsmutablearray
助理工程师
原来NSArray不能修改啊主题 : NSArray 数组中怎么更改值?
级别: 圣骑士
可可豆: 2951 CB
威望: 2951 点
在线时间: 725(时)
发自: Web Page
来源于&&分类
NSArray 数组中怎么更改值?&&&
NSArray *sz = [edit_.text componentsSeparatedByString: @&:&];已经把值赋给了sz数组,现在修改数组下标为2的值,怎么写的?c里面这样写:sz[2] = ‘2’; oc里面怎么写?
级别: 圣骑士
可可豆: 2960 CB
威望: 2960 点
在线时间: 212(时)
发自: Web Page
如果数组可变的话,用NSMutableArray *muArray[myArray replaceObjectAtIndex: withObject:];
Miku碎碎念,碎碎念。
级别: 圣骑士
可可豆: 2951 CB
威望: 2951 点
在线时间: 725(时)
发自: Web Page
&&&&&&&&&&&&&&&&&&&&&&&&if (![st isEqualToString:@&&]) {&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&[sz replaceObjectAtIndex:2:@&00&];&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&& }这样写运行的时候直接退出了。。。。
级别: 圣骑士
可可豆: 2960 CB
威望: 2960 点
在线时间: 212(时)
发自: Web Page
console输出什么?
Miku碎碎念,碎碎念。
级别: 侠客
可可豆: 651 CB
威望: 651 点
在线时间: 138(时)
发自: Web Page
回 2楼(blockg) 的帖子
注意是NSMutableArray, NSArray没有 replaceObjectAtIndex: withObject:&&这个方法,更没有你写的 replaceObjectAtIndex: : 这个方法,当然就退出了
级别: 圣骑士
可可豆: 2951 CB
威望: 2951 点
在线时间: 725(时)
发自: Web Page
是用的NSMutableArray,这是api里面写的replaceObjectsAtIndexes:withObjects:Replaces the objects in the receiving array at specified locations specified with the objects from a given array.- (void)replaceObjectsAtIndexes:(NSIndexSet *)indexes withObjects:(NSArray *)objectsParametersindexesThe indexes of the objects to be replaced.objectsThe objects with which to replace the objects in the receiving array at the indexes specified by indexes. The count of locations in indexes must equal the count of objects.DiscussionThe indexes in indexes are used in the same order as the objects in objects.If objects or indexes is nil this method will raise an exception.AvailabilityAvailable in iOS 2.0 and later.
关注本帖(如果有新回复会站内信通知您)
苹果公司现任CEO是谁?2字 正确答案:库克
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版3221人阅读
iOS实战录(23)
7th,March,2016
1.数组的初始化
1) NSMutableArray *bizArray = [[NSMutableArrayalloc]initWithObjects:tmpDict1,tmpDict2,tmpDict3,nil];
2) 空数组&
&NSMutableArray *tmpArray = [NSMutableArray array];
3) 初始化指定个数的数组
&NSMutableArray *tmp = [NSMutableArrayarrayWithCapacity:3];
2. 数组的增加
[array addObject:@&Four&];
3. 数组元素的删除
[array removeObjectAtIndex:1];
25th,May,2016
1. 判断数组中是否存在某个元素
- (BOOL)containsObject:(ObjectType)anO
- (NSUInteger)indexOfObject:(ObjectType)anO// 间接判断是否存在某个元素
2. 将int放入数组中
大体思路是int是基本数据类型,数组-(void)addObject: 只能添加对象,所以可通过NUNumber将基本数据类型转成对象。然后添加到数组中
然后取数据的时候通过 NSInteger anInteger = [aNumber
integerValue];
未完待续。。。敬请期待
参考资料:
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:37682次
积分:1396
积分:1396
排名:千里之外
原创:105篇
(1)(2)(2)(4)(11)(11)(11)(7)(7)(9)(17)(2)(14)(5)(2)(2)(1)

我要回帖

更多关于 nsarray替换 的文章

 

随机推荐