Skip to content
Browse files

disable choose button while there's no valid data yet

factor test from tableViewDatasource and reuse it
to enable the choose button.
  • Loading branch information...
1 parent 029bf27 commit f20344be3f08485e808c92d41f54c04e8c97d550 @diederich diederich committed Jul 23, 2013
Showing with 21 additions and 3 deletions.
  1. +21 −3 GSDropboxActivity/GSDropboxDestinationSelectionViewController.m
View
24 GSDropboxActivity/GSDropboxDestinationSelectionViewController.m
@@ -75,6 +75,8 @@ - (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
+ [self updateChooseButton];
+
if (self.rootPath == nil)
self.rootPath = @"/";
@@ -87,6 +89,21 @@ - (void)viewWillAppear:(BOOL)animated
self.isLoading = YES;
self.navigationItem.rightBarButtonItem.enabled = YES;
}
+
+- (void) updateChooseButton {
+ NSArray* toolbarButtons = self.toolbarItems;
+ if(toolbarButtons.count < 2) {
+ //Not found
+ return;
+ }
+ UIBarButtonItem *item = toolbarButtons[1];
+ BOOL hasValidData = [self hasValidData];
+ item.enabled = hasValidData;
+}
+
+- (BOOL) hasValidData {
+ BOOL valid = self.subdirectories != nil && self.isLoading == NO;
+ return valid;
}
- (void)viewDidAppear:(BOOL)animated
@@ -140,9 +157,8 @@ - (DBRestClient *)dropboxClient
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
- if (self.isLoading || self.subdirectories == nil || [self.subdirectories count] == 0) {
- return 1;
- }
+ if (![self hasValidData] || self.subdirectories.count < 1) return 1;
+
return [self.subdirectories count];
}
@@ -201,6 +217,7 @@ - (void)restClient:(DBRestClient *)client loadedMetadata:(DBMetadata *)metadata
}
self.subdirectories = [array sortedArrayUsingSelector:@selector(compare:)];
self.isLoading = NO;
+ [self updateChooseButton];
}
- (void)restClient:(DBRestClient *)client loadMetadataFailedWithError:(NSError *)error
@@ -212,6 +229,7 @@ - (void)restClient:(DBRestClient *)client loadMetadataFailedWithError:(NSError *
} else {
self.isLoading = NO;
}
+ [self updateChooseButton];
}
- (void)setIsLoading:(BOOL)isLoading

0 comments on commit f20344b

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