appunite / CLCascade

Twitter-like cascade UI library
http://appunite.com/
Other
504 stars 67 forks source link

Crash on second selection at one stack table controller #28

Closed YuriSarkisyan closed 12 years ago

YuriSarkisyan commented 12 years ago

I'm found a possible bug in realization of CLCascadeView. It reproduced in iOS 4.3 and 5.1 only in release compilation.

If user select table view cell (CLExampleTableViewController) then, by default, a new controller will created and inserted in stack. But, when user select cell in this table again (the same or other no difference), app will crash.

I'm use instruments and zombie profiler and see what CLCascadeView _pages instance is released in method hitTest:withEvent:. I think the reason is wrong return from _pages enumeration. Solution is to not return from inside of while cycle, but outside.

This is my version of this method:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {

id item = nil;
// create enumerator
NSEnumerator* enumerator = [_pages reverseObjectEnumerator];
// enumarate pages
UIView *view = nil;

while ((item = [enumerator nextObject])) {
    if (item != [NSNull null]) {

        UIView* page = (UIView*)item;
        CGRect rect = [_scrollView convertRect:page.frame toView:self];

        if (CGRectContainsPoint(rect, point)) {
            CGPoint newPoint = [self convertPoint:point toView:page];
            view = [page hitTest:newPoint withEvent:event];
        }
    }
} 
if (view != nil) {
    return view;
}

return [super hitTest:point withEvent:event];
}
emilwojtaszek commented 12 years ago

thank you! now it works ;p

YuriSarkisyan commented 12 years ago

One small addition, after assigning a value to a variable view inside the loop, you need to add break; Otherwise not properly defined view in landscape orientation.

emilwojtaszek commented 12 years ago

done :)

jazuara commented 12 years ago

You should remove the break; command, cause make it crash, but thanks for the upper solution!