我有NSMutableArray
喜欢这样:
NSMutableArray *value = [productionSchedule valueForKeyPath:@"Value"];
当填充此NSMutableArray
可能有900行或只有8或12时,无法知道,所以我要做的是处理前15行然后接下来的15行,依此类推直到完成。
我可以用这个处理前15行:
for(int i = 0; i < 15; i++)
{
}
但接下来我将如何处理NSMutableArray
的下一个15?
以下是问题的完整循环:
for(int i = 0; i< [prodSchedSortedKeys count]; i++)
{
NSMutableArray *valueArray = [[NSMutableArray alloc]init];
NSArray *baseLineFinishArray = [value objectAtIndex:i];
for(int j = 0 ;j< [newTaskData count]; j++)
{
ProductionCellData *pModel = [[ProductionCellData alloc]init];
if([[[baseLineFinishArray objectAtIndex:j] valueForKey:@"task"] isEqual: @"Closing Date"])
{
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"yyyy-MM-dd h:mm:ss a"];
pModel.baseLineStart = [self SetSpecialDateFormat:[dateFormatter dateFromString:[[baseLineFinishArray objectAtIndex:j] valueForKey:@"baselinefinish"]]WithOption:0];
pModel.taskItem = [[baseLineFinishArray objectAtIndex:j] valueForKey:@"task"];
[valueArray addObject: pModel];
}
else if([[[baseLineFinishArray objectAtIndex:j] valueForKey:@"task"] isEqual: @"Days To Closing"])
{
[pModel setCellColor:[self SetCellColor:[[[baseLineFinishArray objectAtIndex:j] valueForKey:@"baselinefinish"] intValue]]];
pModel.baseLineStart = [[baseLineFinishArray objectAtIndex:j] valueForKey:@"baselinefinish"];
pModel.taskItem = [[baseLineFinishArray objectAtIndex:j] valueForKey:@"task"];
[valueArray addObject: pModel];
}
else if([[[baseLineFinishArray objectAtIndex:j] valueForKey:@"task"] isEqual: @"Schedule Variance"])
{
[pModel setCellColor:[self SetCellColor:[[[baseLineFinishArray objectAtIndex:j] valueForKey:@"baselinefinish"] intValue]]];
pModel.baseLineStart = [[baseLineFinishArray objectAtIndex:j] valueForKey:@"baselinefinish"];
pModel.taskItem = [[baseLineFinishArray objectAtIndex:j] valueForKey:@"task"];
[valueArray addObject: pModel];
}
else if([[[baseLineFinishArray objectAtIndex:j] valueForKey:@"task"] isEqual: @"Days Of Construction"])
{
[pModel setCellColor:[self SetCellColor:[[[baseLineFinishArray objectAtIndex:j] valueForKey:@"baselinefinish"] intValue]]];
pModel.baseLineStart = [[baseLineFinishArray objectAtIndex:j] valueForKey:@"baselinefinish"];
pModel.taskItem = [[baseLineFinishArray objectAtIndex:j] valueForKey:@"task"];
[valueArray addObject: pModel];
}
else if([[[baseLineFinishArray objectAtIndex:j] valueForKey:@"task"] isEqual: @"NOTES"])
{
pModel.baseLineStart = [[baseLineFinishArray objectAtIndex:j] valueForKey:@"baselinefinish"];
pModel.taskItem = [[baseLineFinishArray objectAtIndex:j] valueForKey:@"task"];
[valueArray addObject: pModel];
}
else if([[[baseLineFinishArray objectAtIndex:j] valueForKey:@"task"] isEqual: @"PDI To Close"])
{
[pModel setCellColor:[self SetCellColor:[[[baseLineFinishArray objectAtIndex:j] valueForKey:@"baselinefinish"] intValue]]];
pModel.baseLineStart = [[baseLineFinishArray objectAtIndex:j] valueForKey:@"baselinefinish"];
pModel.taskItem = [[baseLineFinishArray objectAtIndex:j] valueForKey:@"task"];
[valueArray addObject: pModel];
}
else
{
[pModel setTextCol:[self SetTextColor:[baseLineFinishArray objectAtIndex:j]]];
[pModel setCellColor:[self SetCellColor:[self DateDifference:[baseLineFinishArray objectAtIndex:j]]]];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd h:mm:ss a"];
pModel.baseLineStart = [self SetSpecialDateFormat:[dateFormatter dateFromString:[[baseLineFinishArray objectAtIndex:j] valueForKey:@"baselinefinish"]]WithOption:0];
pModel.actualFinish = [self SetSpecialDateFormat:[dateFormatter dateFromString:[[baseLineFinishArray objectAtIndex:j] valueForKey:@"actualenddate"]]WithOption:0];
pModel.taskItem = [[baseLineFinishArray objectAtIndex:j] valueForKey:@"task"];
[valueArray addObject:pModel];
[dateFormatter release]; dateFormatter=nil;
}
[pModel release];
pModel = nil;
}
[finalProductionSchedule setObject:valueArray forKey:[prodSchedSortedKeys objectAtIndex:i]];
[valueArray release];
valueArray = nil;
}
[prodSchedSortedKeys count]
可能超过900,或者只有12,它是数据行数。
在做了一些调试之后,我已经确定这会减慢一切并占用内存:
- (NSString *)SetSpecialDateFormat:(NSString *)date
{
NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
[dateFormat setDateFormat:@"dd-MM-yyyy"];
NSString *theDate = date;
NSArray *array = [theDate componentsSeparatedByString:@" "];
dateFormat = nil;
return [array objectAtIndex:0];
}