Skip to content

Commit

Permalink
added reload button to TTTable error view
Browse files Browse the repository at this point in the history
  • Loading branch information
Adar Porat committed Jan 12, 2012
1 parent 1135b57 commit 983e335
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 3 deletions.
Binary file added 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.
Binary file added 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.
Binary file added 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.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/Three20Style/Sources/TTDefaultStyleSheet.m
Expand Up @@ -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];
}
}


///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
10 changes: 8 additions & 2 deletions src/Three20UI/Headers/TTErrorView.h
Expand Up @@ -14,19 +14,25 @@
// 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;

@end
20 changes: 19 additions & 1 deletion src/Three20UI/Sources/TTErrorView.m
Expand Up @@ -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;


Expand All @@ -36,6 +37,8 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
@implementation TTErrorView

@synthesize reloadButton = _reloadButton;


///////////////////////////////////////////////////////////////////////////////////////////////////
- (id)initWithTitle:(NSString*)title subtitle:(NSString*)subtitle image:(UIImage*)image {
Expand Down Expand Up @@ -72,6 +75,13 @@ - (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;
Expand All @@ -83,6 +93,7 @@ - (void)dealloc {
TT_RELEASE_SAFELY(_imageView);
TT_RELEASE_SAFELY(_titleView);
TT_RELEASE_SAFELY(_subtitleView);
TT_RELEASE_SAFELY(_reloadButton);

[super dealloc];
}
Expand Down Expand Up @@ -116,6 +127,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) {
Expand All @@ -132,7 +145,10 @@ - (void)layoutSubviews {
}
if (_subtitleView.text.length) {
_subtitleView.origin = CGPointMake(floor(self.width/2 - _subtitleView.width/2), top);
top += _subtitleView.height + kVPadding3;
}

_reloadButton.origin = CGPointMake(floor(self.width/2 - _reloadButton.width/2), top);
}


Expand Down Expand Up @@ -178,4 +194,6 @@ - (void)setImage:(UIImage*)image {
}




@end
3 changes: 3 additions & 0 deletions src/Three20UI/Sources/TTTableViewController.m
Expand Up @@ -490,6 +490,9 @@ - (void)showError:(BOOL)show {
TTErrorView* errorView = [[[TTErrorView alloc] initWithTitle:title
subtitle:subtitle
image:image] autorelease];
[errorView.reloadButton addTarget:self
action:@selector(reload)
forControlEvents:UIControlEventTouchUpInside];
errorView.backgroundColor = _tableView.backgroundColor;
self.errorView = errorView;

Expand Down

0 comments on commit 983e335

Please sign in to comment.