I have a block of code that I am trying to optimize. The method is being used a lot so any little improvement would greatly increase performance.
- (CGRect)calculateRectForItemAtIndex:(NSIndexPath*)path {
//Get the x position stored in an NSMutableArray
double x = [self.sectionXPlacementArray[path.section] doubleValue];
double y = 0;
double height = 0;
//If this is the first row it is a header so treat it different
if (path.row == 0) {
height = self.defaultHeaderHeight;
y = 0;
}
else {
height = self.defaultHeight;
//Calculate the Y placement
y = (path.row-1)*self.defaultHeight+self.defaultHeaderHeight;
}
//Build and return a CGRect
return CGRectMake(x, y, [self.headerSizes[self.headers[path.section]] doubleValue],height);
}
Here is some more information:
1) headerSizes is a NSMutableDictionary that looks like so:
{
Header1 = 135;
Header2 = 130;
Header3 = 130;
}
2) headers is a NSMutableArray that looks like this:
(
Header1,
Header2,
Header3
)
These values in the app will not be Header_. They will be dynamic NSStrings like "City" or "State". headerSizes will contain the width that should be used for each header.