我一直在挣扎与创建,访问和从动态布尔数组一个多星期,现在更新价值的最佳途径。
@interface myDelegate : NSObject
{
NSMutableArray *aShowNote;
}
@property (nonatomic, copy) NSMutableArray *aShowNote;
这是我已经初始化我的数组:
NSMutableArray *aShow = [[NSMutableArray alloc] init];
for (i=0; i < c; i++)
[aShow addObject:[NSNumber numberWithBool:false]];
self.aShowNote = aShow;
这似乎是工作确定,但我感到困惑,为什么每个元素与同一地址初始化。
但后来我在我的研究中已经发现迄今是好像你需要的,如果你想改变它的值来代替对象:
myDelegate *appDelegate = (myDelegate *)[[UIApplication sharedApplication] delegate];
NSInteger recordIndex = 1;
NSNumber *myBoolNo = [appDelegate.aShowNote objectAtIndex:recordIndex];
BOOL showNote = ![myBoolNo boolValue];
[appDelegate.aShowNote replaceObjectAtIndex:recordIndex withObject:[NSNumber numberWithBool:showNote]];
但这种方法只是似乎过于复杂(和它崩溃过)。
终止应用程序由于未捕获exception'NSInvalidArgumentException '原因:' - [__ NSArrayI replaceObjectAtIndex:withObject:]:无法识别的选择发送到实例0x5b51d00
任何指针,以改善这些代码(当然,使其工作)将是非常感激地接受。
谢谢
Iphaaw