Skip to content

Commit

Permalink
Fix a footer/header rendering error. Add code for testing scroll to l…
Browse files Browse the repository at this point in the history
…oad more.
  • Loading branch information
Xenofex committed Jan 17, 2012
1 parent 95ce831 commit 0df9820
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 38 deletions.
5 changes: 4 additions & 1 deletion StreamView/EKStreamView.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ - (void)reloadData
[cellHeightsByColumn removeAllObjects];
[rectsForCells removeAllObjects];
[cellCache removeAllObjects];
[headerView removeFromSuperview];
[footerView removeFromSuperview];

if ([delegate respondsToSelector:@selector(headerForStreamView:)]) {
headerView = [[delegate headerForStreamView:self] retain];
Expand Down Expand Up @@ -323,7 +325,8 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{

if ([streamView.delegate respondsToSelector:@selector(scrollViewDidEndDragging:willDecelerate:)])
[streamView.delegate scrollViewDidEndDragging:streamView willDecelerate:decelerate];
}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
Expand Down
2 changes: 2 additions & 0 deletions StreamView/EKViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
@interface EKViewController : UIViewController<EKStreamViewDelegate>
{
NSMutableArray *randomHeights;
int page;
}

@property (retain, nonatomic) IBOutlet EKStreamView *stream;

@end
30 changes: 26 additions & 4 deletions StreamView/EKViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import "EKViewController.h"
#import "MyCell.h"

static int MaxPage = 3;

@implementation EKViewController
@synthesize stream;

Expand Down Expand Up @@ -38,6 +40,7 @@ - (void)viewDidLoad
CGFloat h = arc4random() % 200 + 50.f;
[randomHeights addObject:[NSNumber numberWithFloat:h]];
}
stream.scrollsToTop = YES;

[stream reloadData];
}
Expand Down Expand Up @@ -105,10 +108,29 @@ - (UIView *)headerForStreamView:(EKStreamView *)streamView

- (UIView *)footerForStreamView:(EKStreamView *)streamView
{
MyCell *footer = [[[MyCell alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 60)] autorelease];
footer.label.text = @"This is the footer";

return footer;
if (page <= MaxPage) {
MyCell *footer = [[[MyCell alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 60)] autorelease];
footer.label.text = @"This is the footer";

return footer;
} else {
return nil;
}
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (ABS(scrollView.contentSize.height - scrollView.frame.size.height - scrollView.contentOffset.y) < 3
&& page <= MaxPage) {
for (int i = 0; i < 100; i++) {
CGFloat h = arc4random() % 200 + 50.f;
[randomHeights addObject:[NSNumber numberWithFloat:h]];
}

page++;

[stream reloadData];
}
}

@end
34 changes: 1 addition & 33 deletions StreamView/EKViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
<int key="NSvFlags">274</int>
<string key="NSFrameSize">{320, 460}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
<string key="NSReuseIdentifierKey">_NS:190</string>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIMultipleTouchEnabled">YES</bool>
Expand All @@ -49,7 +48,6 @@
</array>
<string key="NSFrame">{{0, 20}, {320, 460}}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="442277849"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">3</int>
Expand Down Expand Up @@ -139,37 +137,7 @@
<nil key="sourceID"/>
<int key="maxID">11</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
<string key="className">EKStreamView</string>
<string key="superclassName">UIScrollView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/EKStreamView.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">EKViewController</string>
<string key="superclassName">UIViewController</string>
<object class="NSMutableDictionary" key="outlets">
<string key="NS.key.0">stream</string>
<string key="NS.object.0">EKStreamView</string>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
<string key="NS.key.0">stream</string>
<object class="IBToOneOutletInfo" key="NS.object.0">
<string key="name">stream</string>
<string key="candidateClassName">EKStreamView</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/EKViewController.h</string>
</object>
</object>
</array>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes"/>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
Expand Down

0 comments on commit 0df9820

Please sign in to comment.