NSMutableArray初始化并销毁值

时间:2014-07-07 07:34:38

标签: xcode nsmutablearray

我正在创建一个Xcode应用程序,我需要创建一个NSMutableArray,当我的开关打开时以及当交换机关闭分配给也分配给NSMutableArray的交换机的值时,它会被初始化从数组中销毁,代码应该如何?我已经初始化了我的开关,但我不知道如何添加/销毁NSMUtableArray中的值

2 个答案:

答案 0 :(得分:0)

- (void)changeState:(id)sender 
{
    UICustomSwitch* currentSwitch = (UICustomSwitch*)sender;
    if ([currentSwitch isOn]) {
        [myMutableArray addObject:currentSwitch.myCustomValue];
    } else {
        [myMutableArray removeObject:currentSwitch.myCustomValue];
    }
}

答案 1 :(得分:0)

如果你必须在NSMutableArray中添加新对象

ringsArray.addObject(_ring)

如果在NSMutableArray中插入对象

ringsArray.insertObject("Value", atIndex: position)

与删除值

相同
ringsArray.removeObject("")
ringsArray.removeObjectAtIndex(position)
相关问题