0

I'm doing an iPhone app in iOS 5.

In that I'm expanding and reloading the uitableview while recognizing the pinch gesture.

It works great in simulator. But in device it works very slow. For example in device after the UIGestureRecognizerStateEnded only all the rows will be expanded, but in simulator the rows are expanding and reloading while UIGestureRecognizerStateChanged itself.

any suggestions for memory issues?

my code is here

if (pinchRecognizer.state == UIGestureRecognizerStateBegan) {

    self.initialPinchHeight = rowHeight;

    [self updateForPinchScale:pinchRecognizer.scale];
}
else {
    if (pinchRecognizer.state == UIGestureRecognizerStateChanged) {
        [self updateForPinchScale:pinchRecognizer.scale];

    }
    else if ((pinchRecognizer.state == UIGestureRecognizerStateCancelled) || (pinchRecognizer.state == UIGestureRecognizerStateEnded)) {
    }
}

-(void)updateForPinchScale:(CGFloat)scale{

CGFloat newHeight = round(MAX(self.initialPinchHeight * scale, DEFAULT_ROW_HEIGHT));

rowHeight = round(MIN(30.0, newHeight));
/*
 Switch off animations during the row height resize, otherwise there is a lag before the user's action is seen.
 */
BOOL animationsEnabled = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
[self.tableView beginUpdates];
NSArray *visibleRows = [self.tableView indexPathsForVisibleRows];
[self.tableView reloadRowsAtIndexPaths:visibleRows withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
[UIView setAnimationsEnabled:animationsEnabled];
}
Jirune
  • 2,310
  • 3
  • 21
  • 19

1 Answers1

0

Before trying to figure out what to optimize, you should measure where the problem is. You can do this using the Time Profile and Core Animation instruments. Use Xcode's Product menu and select Profile. Make sure you profile while you are attached to the device, which, as you have noticed, has different performance characteristics than the simulator.

The Time Profile instrument will help you identify work done on the CPU. The Core Animation instrument will help you identify work being done by Core Animation both on the CPU and GPU. Pay attention to the Core Animation instrument's Debug Option checkboxes. They're a little cryptic, but will help you visually identify the parts of your UI that are making the Core Animation do a lot of work.

Documentation on the different instruments available for iOS are here.

I also recommend the WWDC video covering Core Animation.

Doug Richardson
  • 10,483
  • 6
  • 51
  • 77
  • hi thanks for you reply, in my code i did one mistake. The mistake is I reloaded rows in between beginupdates and endupdates. After fixed this my app is working normal on my iPhone. – Jirune Apr 26 '12 at 06:02