Problem with viewcell


I’m a real beginner at all this and am in need of some help.

I’m trying to use a version of the code that pops up a large image when someone taps on the thumbnail. But when I do, I hit a problem.

It generally happens like this. The app starts up in a table VC. Tapping a cell takes you to another table VC. These work fine and I can switch back and forth between these two VCs all day with the app responding quickly. From the second TVC, tapping a row takes you to a third VC. This contains the code I’ve borrowed from this chapter.

So far so good. But if I try to back up to the previous VC quickly, a lot of objects seem to be added to the heap, over the course of about 30 secs, even though I and the app aren’t doing anything. The heap allocations then drop back over a period of about 8 seconds. During this time, the UI is unresponsive and nothing happens - ie, the view doesn’t switch. Once the heap allocations drop back, the view switches. After that, any change (up or down the stack of the navigation controller) causes this process of objects being added and freezing the UI.

When I look at the ‘Responsible Callers’ in Instruments, I see a lot of things like
-[UIView(Hierarchy) subviews]
-[NSObject(NSDelayedPerforming) performSelector:withObject:afterDelay:inModes:]
and many other things I don’t understand.

If I comment out the section after ‘FOR IMAGE VIEWING’ until the end of the block, the problem doesn’t occur. The code in question is:

[code]- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
static NSString *cellIdentifier = @“ZSShotTableViewCell”;
ZSShotTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

ZSShotCD *item = [self.frc objectAtIndexPath:indexPath];
cell.shotNumberAsStringLabel.text = item.shotNumberAsString;
cell.shotDescriptionLabel.text = [item MainText];
cell.shotSubtextLabel.text = [item detailText];
cell.shotThumbnail.image = [UIImage imageWithData:item.thumbnail];

// isDone toggle button
ZSCellActionButton *doneButton = [ZSCellActionButton buttonWithType:UIButtonTypeRoundedRect];
doneButton.frame=CGRectMake(50, 10, 32, 32);
[doneButton setImage:[UIImage imageNamed:@"line_check.png"] forState:UIControlStateNormal];
[doneButton.imageView setAlpha:0.5];
[doneButton addTarget:self action:@selector(toggleIsDone:) forControlEvents:UIControlEventTouchUpInside];
doneButton.indexPath = indexPath;
cell.accessoryView = doneButton;

__weak ZSShotTableViewCell *weakCell = cell;
cell.actionBlock = ^{
    ZSShotTableViewCell *strongCell = weakCell;
    NSString *itemKey = item.shotID;
    // Get the image from the store
    UIImage *img = [[ZSShotImageStore shotImageStore] imageForKey:itemKey
    if (img) {      // If there's no image, there's nothing to do.
        NSLog(@"Image for %@", item.shotDescription);
        ZSImageVC *ivc = [[ZSImageVC alloc] init];
        ivc.image = img;
        if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
            // iPAD
            // Make a rectangle for the frame of the thumbnail
            CGRect rect = [self.view convertRect:strongCell.shotThumbnail.bounds
            // Present a 600x600 popover from the rect
            self.imagePopover = [[UIPopoverController alloc]
            self.imagePopover.delegate = self;
            self.imagePopover.popoverContentSize = CGSizeMake(600, 600);
            [self.imagePopover presentPopoverFromRect:rect
        } else {
            // iPHONE
            [self.navigationController pushViewController:ivc animated:YES];
return cell;


Like I said, I’m pretty much a newb at this, so if anyone could suggest where the problem might be coming from, I’d be grateful.


Just a quick update: I was concerned that I’d added that ‘doneButton’ programmatically and not provided any constraints for it. So I’ve changed the code so that the button is in the XIB, with all necessary constraints. So that bit of the code has changed to:

[cell.shotDoneButton addTarget:self action:@selector(toggleIsDone:) forControlEvents:UIControlEventTouchUpInside]; cell.shotDoneButton.indexPath = indexPath;

(The button is an instance of my own subclass of UIButton which simply adds an indexPath property).