Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #749 from aporat/tterrorview-button

[UI] Reload buttons in TTTableViewController error views
  • Loading branch information...
commit c167505a5872d01ef756c4ffc51fc0420f742783 2 parents 5560bcb + aba9621
@aporat aporat authored
View
BIN  src/Three20.bundle/images/reloadButton.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  src/Three20.bundle/images/reloadButton@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  src/Three20.bundle/images/reloadButtonActive.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  src/Three20.bundle/images/reloadButtonActive@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
18 src/Three20Style/Sources/TTDefaultStyleSheet.m
@@ -826,6 +826,24 @@ - (UIColor*)searchTableSeparatorColor {
return [UIColor colorWithWhite:0.85 alpha:1];
}
+///////////////////////////////////////////////////////////////////////////////////////////////////
+- (TTStyle*)tableReloadButton:(UIControlState)state {
+ if (state == UIControlStateHighlighted) {
+ return
+ [TTImageStyle styleWithImageURL:@"bundle://Three20.bundle/images/reloadButtonActive.png"
+ defaultImage:nil
+ contentMode:UIViewContentModeCenter
+ size:CGSizeMake(50,50) next:nil];
+
+ } else {
+ return
+ [TTImageStyle styleWithImageURL:@"bundle://Three20.bundle/images/reloadButton.png"
+ defaultImage:nil
+ contentMode:UIViewContentModeCenter
+ size:CGSizeMake(50,50) next:nil];
+ }
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
View
15 src/Three20UI/Headers/TTErrorView.h
@@ -14,19 +14,30 @@
// limitations under the License.
//
-#import <Foundation/Foundation.h>
-#import <UIKit/UIKit.h>
+// UI
+#import "Three20UI/TTButton.h"
@interface TTErrorView : UIView {
UIImageView* _imageView;
UILabel* _titleView;
UILabel* _subtitleView;
+ TTButton* _reloadButton;
}
@property (nonatomic, retain) UIImage* image;
@property (nonatomic, copy) NSString* title;
@property (nonatomic, copy) NSString* subtitle;
+@property (nonatomic, copy) TTButton* reloadButton;
+
+/**
+ * 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
27 src/Three20UI/Sources/TTErrorView.m
@@ -27,7 +27,8 @@
#import "Three20Core/TTCorePreprocessorMacros.h"
static const CGFloat kVPadding1 = 30.0f;
-static const CGFloat kVPadding2 = 20.0f;
+static const CGFloat kVPadding2 = 10.0f;
+static const CGFloat kVPadding3 = 15.0f;
static const CGFloat kHPadding = 10.0f;
@@ -36,6 +37,20 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation TTErrorView
+@synthesize reloadButton = _reloadButton;
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+- (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 {
@@ -83,6 +98,7 @@ - (void)dealloc {
TT_RELEASE_SAFELY(_imageView);
TT_RELEASE_SAFELY(_titleView);
TT_RELEASE_SAFELY(_subtitleView);
+ TT_RELEASE_SAFELY(_reloadButton);
[super dealloc];
}
@@ -116,6 +132,8 @@ - (void)layoutSubviews {
totalHeight += (totalHeight ? kVPadding2 : 0) + _subtitleView.height;
}
+ totalHeight += (totalHeight ? kVPadding3 : 0) + _reloadButton.height;
+
CGFloat top = floor(self.height/2 - totalHeight/2);
if (canShowImage) {
@@ -132,6 +150,11 @@ - (void)layoutSubviews {
}
if (_subtitleView.text.length) {
_subtitleView.origin = CGPointMake(floor(self.width/2 - _subtitleView.width/2), top);
+ top += _subtitleView.height + kVPadding3;
+ }
+
+ if (_reloadButton!=nil) {
+ _reloadButton.origin = CGPointMake(floor(self.width/2 - _reloadButton.width/2), top);
}
}
@@ -178,4 +201,6 @@ - (void)setImage:(UIImage*)image {
}
+
+
@end
View
7 src/Three20UI/Sources/TTTableViewController.m
@@ -491,7 +491,14 @@ - (void)showError:(BOOL)show {
TTErrorView* errorView = [[[TTErrorView alloc] initWithTitle:title
subtitle:subtitle
image:image] autorelease];
+ 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");
}
Please sign in to comment.
Something went wrong with that request. Please try again.