大佬教程收集整理的这篇文章主要介绍了ios – NSMutableArray属性初始化和更新,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
出于某种原因,我无法理解需要做的事情,特别是在声明和初始化步骤中.
我相信这可以是私有财产.
@property (strong,nonatomiC) NSMutableArray *scores; @synthesize scores = _scores;
然后在viewDidLoad我尝试这样的东西,但得到@L_874_1@错误.我想,我只需要语法方面的帮助.或者我遗漏了一些非常基本的东西.
self.scores = [[NSMutableArray alloc] initWithObjects:@0,@0,nil];
这是初始化它的合适方式吗?然后我如何将(NSnumber *)updateValue添加到第n个值?
编辑:我想我弄清楚了.
-(void)updatescoreForBase:(int)baseIndex byIncrement:(int)scoreAdjustmentamount { int prevIoUsValue = [[self.scores objectATindex:baseIndex] intValue]; int updatedValue = prevIoUsValue + scoreAdjustmentamount; [_scores replaceObjectATindex:baseIndex withObject:[NSnumber numberWithInt:updatedValue]]; }
有没有更好的方法呢?
这两者都相似,完全有效.
_scores = [[NSMutableArray alloc] initWithObjects:@0,nil];
要么,
self.scores=[[NSMutableArray alloc]initWithObjects:@0,nil];
你的上@L_874_1@问题……然后我如何将(NSnumber *)updateValue添加到第n个值?
如果你添加了对象:它将被添加到最后.您需要在所需索引中插入Object:aTindex:并且所有后续对象都将转移到下@L_874_1@索引.
NSInteger nthValue=12; [_scores insertObject:updateValue aTindex:nthValue];
编辑:
编辑完成后
NSInteger prevIoUsValue = [[_scores objectATindex:baseIndex] IntegerValue]; NSInteger updatedValue = prevIoUsValue + scoreAdjustmentamount; [_scores replaceObjectATindex:baseIndex withObject:[NSnumber numberWithInt:updatedValue]];
以上是大佬教程为你收集整理的ios – NSMutableArray属性初始化和更新全部内容,希望文章能够帮你解决ios – NSMutableArray属性初始化和更新所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。