Skip to content
This repository has been archived by the owner on Nov 30, 2019. It is now read-only.

Commit

Permalink
added errors view refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwijas committed Feb 23, 2013
1 parent e9a468d commit 030dada
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 190 deletions.
2 changes: 1 addition & 1 deletion Project/UISS.xcodeproj/project.pbxproj
Expand Up @@ -790,10 +790,10 @@
E1B438B7143F668000F87518 /* UISS.h */,
E1B438B8143F668000F87518 /* UISS.m */,
E1914CAD158F99BB00E04977 /* UISSStyle.h */,
E1914CAE158F99BB00E04977 /* UISSStyle.m */,
E145C8611584DCC70087BB1B /* UISSConfig.h */,
E145C8621584DCC70087BB1B /* UISSConfig.m */,
E1B438B5143F668000F87518 /* Supporting Files */,
E1914CAE158F99BB00E04977 /* UISSStyle.m */,
);
path = UISS;
sourceTree = "<group>";
Expand Down
1 change: 1 addition & 0 deletions Project/UISS/UISSConsoleViewController.h
Expand Up @@ -9,6 +9,7 @@
#import <UIKit/UIKit.h>

@class UISS;
@class UISSErrorsViewController;

@interface UISSConsoleViewController : UITabBarController

Expand Down
41 changes: 33 additions & 8 deletions Project/UISS/UISSConsoleViewController.m
Expand Up @@ -14,28 +14,30 @@
@interface UISSConsoleViewController ()

@property(nonatomic, strong) UISS *uiss;
@property(nonatomic, strong) UISSErrorsViewController *errorsViewController;

@end

@implementation UISSConsoleViewController

@synthesize uiss = _uiss;

- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}


- (id)initWithUISS:(UISS *)uiss; {
self = [super init];
if (self) {
self.uiss = uiss;

// Errors
UISSErrorsViewController *errorsViewController = [[UISSErrorsViewController alloc] init];
errorsViewController.navigationItem.leftBarButtonItem = [self createCloseBarButton];
if (self.uiss.style.errors.count) {
errorsViewController.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",
self.uiss.style.errors.count];
}
errorsViewController.errors = self.uiss.style.errors;
self.errorsViewController = [[UISSErrorsViewController alloc] init];
self.errorsViewController.navigationItem.leftBarButtonItem = [self createCloseBarButton];
[self updateErrors];

UINavigationController *errorsNavigationController = [[UINavigationController alloc] initWithRootViewController:errorsViewController];
UINavigationController *errorsNavigationController = [[UINavigationController alloc] initWithRootViewController:self.errorsViewController];

// Config
UISSSettingsViewController *settingsViewController = [[UISSSettingsViewController alloc] initWithUISS:self.uiss];
Expand All @@ -56,10 +58,33 @@ - (id)initWithUISS:(UISS *)uiss; {
} else {
self.selectedViewController = configNavigationController;
}

[self registerForNotifications];
}
return self;
}

- (void)registerForNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateErrors)
name:UISSStyleDidParseDataNotification
object:self.uiss.style];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateErrors)
name:UISSStyleDidParseDictionaryNotification
object:self.uiss.style];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateErrors)
name:UISSDidApplyStyleNotification
object:self.uiss];
}

- (void)updateErrors {
self.errorsViewController.errors = self.uiss.style.errors;
}

- (UIBarButtonItem *)createCloseBarButton {
return [[UIBarButtonItem alloc] initWithTitle:@"Close"
style:UIBarButtonItemStyleBordered
Expand Down
2 changes: 1 addition & 1 deletion Project/UISS/UISSErrorsViewController.h
Expand Up @@ -10,6 +10,6 @@

@interface UISSErrorsViewController : UITableViewController

@property (nonatomic, strong) NSArray *errors;
@property (nonatomic, copy) NSArray *errors;

@end
45 changes: 28 additions & 17 deletions Project/UISS/UISSErrorsViewController.m
Expand Up @@ -14,12 +14,11 @@ @interface UISSErrorsViewController ()

@implementation UISSErrorsViewController

@synthesize errors=_errors;
@synthesize errors = _errors;

#pragma mark - Table view data source

- (id)init
{
- (id)init {
self = [super init];
if (self) {
self.title = @"Errors";
Expand All @@ -28,39 +27,51 @@ - (id)init
return self;
}

- (void)viewDidLoad;
{
- (void)viewDidLoad; {
[super viewDidLoad];

self.tableView.rowHeight = 100;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
- (void)setErrors:(NSArray *)errors {
_errors = errors;

[self update];
}

- (void)update {
if (self.errors.count) {
self.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d", self.errors.count];
} else {
self.tabBarItem.badgeValue = nil;
}

[self.tableView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.errors.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ErrorCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

NSError *error = [self.errors objectAtIndex:(NSUInteger) indexPath.row];

cell.selectionStyle = UITableViewCellSelectionStyleNone;

cell.textLabel.numberOfLines = 0;
cell.textLabel.text = error.localizedDescription;

return cell;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;
{
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation; {
return YES;
}

Expand Down

0 comments on commit 030dada

Please sign in to comment.