我想連續運行函數中創建一個NSMutableArray的,只是一旦如此,它並不能保持初始化值(從而取代了變更值)作爲函數被反覆稱爲初始化它的值。我的問題是,當我嘗試初始化if語句中的值時,數組中的值不會更改,當我期望打印「值爲1」時,它會保持打印「值爲0」爲什麼我的NSMutableArray在Objective-C中的if語句中更改時不會更改它的值?
這是我的相關代碼:
@property (nonatomic, strong) NSMutableArray * shapeMarked;
@synthesize shapeMarked;
//locationManager is the function that's continuously called
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
//event count is an integer that continuously increases by one each time the
//parent function is called, this if statement is used so that it only happens
//once
if(eventcount == 1){
for (int i = 0; i < 5; i++){
BOOL b = YES;
[shapeMarked addObject:[NSNumber numberWithBool:b]];
NSLog(@"value is %d", [[shapeMarked objectAtIndex:i] boolValue]);
}
}
}
'eventcount == 1'曾經匹配過嗎?在這種情況下添加一個NSLog。另外,shapeMarked實際上是一個有效的NSArray?添加一個NSLog(@「array:%@」,shapeMarked);' – Till 2012-04-26 20:14:35
當我添加NSLog(@「array ...);它輸出」array:(null)。我知道「事件計數== 1」匹配,因爲NSLog輸出,如果它不匹配我不會得到輸出,因爲在if語句中調用NSLog。 – user671891 2012-04-26 20:22:08
[NSMutableArray addObject not working]可能的重複(http://stackoverflow.com/questions/1827058/nsmutablearray-addobject-not-working) – 2012-04-26 20:36:36