Skip to content
Browse files

adding the reload button as optional function in the datasource

  • Loading branch information...
1 parent 983e335 commit aba9621a43288476954d76907bde32e1e92440fa Adar Porat committed Jan 17, 2012
View
9 src/Three20UI/Headers/TTErrorView.h
@@ -31,8 +31,13 @@
/**
- * creates an error view
- */
+ * creates an error view
+ */
- (id)initWithTitle:(NSString*)title subtitle:(NSString*)subtitle image:(UIImage*)image;
+/**
+ * adds a reload button into the error view
+ */
+- (void)addReloadButton;
+
@end
View
6 src/Three20UI/Headers/TTTableViewDataSource.h
@@ -54,6 +54,12 @@
- (NSString*)subtitleForEmpty;
+
+/**
+ * return YES to include a reload button in the TTErrorView.
+ */
+- (BOOL)reloadButtonForEmpty;
+
- (UIImage*)imageForError:(NSError*)error;
- (NSString*)titleForError:(NSError*)error;
View
23 src/Three20UI/Sources/TTErrorView.m
@@ -41,6 +41,18 @@ @implementation TTErrorView
///////////////////////////////////////////////////////////////////////////////////////////////////
+- (void)addReloadButton {
+ _reloadButton = [[TTButton buttonWithStyle:@"tableReloadButton:"] retain];
+ [_reloadButton setImage:@"bundle://Three20.bundle/images/reloadButton.png"
+ forState:UIControlStateNormal];
+ [_reloadButton sizeToFit];
+ [self addSubview:_reloadButton];
+
+ [self layoutSubviews];
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
- (id)initWithTitle:(NSString*)title subtitle:(NSString*)subtitle image:(UIImage*)image {
self = [self init];
if (self) {
@@ -75,13 +87,6 @@ - (id)initWithFrame:(CGRect)frame {
_subtitleView.textAlignment = UITextAlignmentCenter;
_subtitleView.numberOfLines = 0;
[self addSubview:_subtitleView];
-
- _reloadButton = [[TTButton buttonWithStyle:@"tableReloadButton:"] retain];
- [_reloadButton setImage:@"bundle://Three20.bundle/images/reloadButton.png"
- forState:UIControlStateNormal];
- [_reloadButton sizeToFit];
- [self addSubview:_reloadButton];
-
}
return self;
@@ -148,7 +153,9 @@ - (void)layoutSubviews {
top += _subtitleView.height + kVPadding3;
}
- _reloadButton.origin = CGPointMake(floor(self.width/2 - _reloadButton.width/2), top);
+ if (_reloadButton!=nil) {
+ _reloadButton.origin = CGPointMake(floor(self.width/2 - _reloadButton.width/2), top);
+ }
}
View
10 src/Three20UI/Sources/TTTableViewController.m
@@ -490,10 +490,14 @@ - (void)showError:(BOOL)show {
TTErrorView* errorView = [[[TTErrorView alloc] initWithTitle:title
subtitle:subtitle
image:image] autorelease];
- [errorView.reloadButton addTarget:self
- action:@selector(reload)
- forControlEvents:UIControlEventTouchUpInside];
+ if ([_dataSource reloadButtonForEmpty]) {
+ [errorView addReloadButton];
+ [errorView.reloadButton addTarget:self
+ action:@selector(reload)
+ forControlEvents:UIControlEventTouchUpInside];
+ }
errorView.backgroundColor = _tableView.backgroundColor;
+
self.errorView = errorView;
} else {
View
6 src/Three20UI/Sources/TTTableViewDataSource.m
@@ -370,6 +370,12 @@ - (NSString*)subtitleForEmpty {
///////////////////////////////////////////////////////////////////////////////////////////////////
+- (BOOL)reloadButtonForEmpty {
+ return YES;
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
- (UIImage*)imageForError:(NSError*)error {
return nil;
}
View
6 src/Three20UI/Sources/TTThumbsDataSource.m
@@ -197,6 +197,12 @@ - (NSString*)subtitleForEmpty {
///////////////////////////////////////////////////////////////////////////////////////////////////
+- (BOOL)reloadButtonForEmpty {
+ return NO;
+}
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
- (UIImage*)imageForError:(NSError*)error {
return TTIMAGE(@"bundle://Three20.bundle/images/photoDefault.png");
}

0 comments on commit aba9621

Please sign in to comment.
Something went wrong with that request. Please try again.