views:

99

answers:

1

My app has a paged scrollView with a tableView in each page. At the bottom of the screen I placed an ad banner, which should hide as the ads become unavailable and reappear when they are loaded. This banner is placed below the scrollView and is not affected by the user scrolling left-right through pages or up-down through the table.

So I resize that scrollView whenever needed with something like this:

NSInteger offset = -50;
if (self.bannerIsVisible) offset = 50;
CGRect frame = scrollView.frame;
frame.size.height += offset;
scrollView.contentSize = CGSizeMake(frame.size.width * pages, frame.size.height);
scrollView.frame = frame;

That last line is causing me problems. Sometimes everything works just fine and it resizes the scrollView and all its content perfectly. Other times, it crashes with this in console:

2010-07-27 10:25:31.779 MyAPP[8026:207] -[__NSArrayM tableView:cellForRowAtIndexPath:]: unrecognized selector sent to instance 0x736eb20
2010-07-27 10:25:31.781 MyAPP[8026:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM tableView:cellForRowAtIndexPath:]: unrecognized selector sent to instance 0x736eb20'
*** Call stack at first throw:
(
    0   CoreFoundation                 0x026cb919 __exceptionPreprocess + 185
    1   libobjc.A.dylib                0x028195de objc_exception_throw + 47
    2   CoreFoundation                 0x026cd42b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                 0x0263d116 ___forwarding___ + 966
    4   CoreFoundation                 0x0263ccd2 _CF_forwarding_prep_0 + 50
    5   UIKit                          0x003a3a3f -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 619
    6   UIKit                          0x00399ad2 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
    7   UIKit                          0x003ae40c -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
    8   UIKit                          0x003a60d7 -[UITableView(_UITableViewPrivate) _setNeedsVisibleCellsUpdate:withFrames:] + 372
    9   UIKit                          0x003a37cd -[UITableView setFrame:] + 266
    10  UIKit                          0x00367ae8 -[UIView(Geometry) resizeWithOldSuperviewSize:] + 385
    11  UIKit                          0x0036ba2b -[UIView(Geometry) resizeSubviewsWithOldSize:] + 273
    12  UIKit                          0x00367f79 -[UIView(Geometry) setFrame:] + 497
    13  UIKit                          0x0038085f -[UIScrollView setFrame:] + 617
    14  MyAPP                          0x0000a678 -[MyViewController toggleBanner] + 893

Why is this happening, and why only sometimes? More to the point, how can I reliably change the size of my scrollView?

+1  A: 

That looks very much like the object that was your table view's data source was released and so the delegate method was sent to a different object. This is a memory management issue, so you might try running your app with the Zombies instrument to see if it catches the issue.

Jason Foreman