I am trying to hide my UITableView conditionally based on an if statement.
Now I have the following code and when I load the app, it checks the condition and this works and when I press the Reload button, it checks and it works.
I also have a ViewWillAppear statement, which would work if I change the view and come back to the TableView again.
Now my question is what void or method do I need to make this automatic – ie without having to press a button or change views??
Now the code shows the 3 methods I have, and they all more or less have the same code, to show what I have thus far.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
// Change Color of TableView if Empty
if (![[self.fetchedResultsController fetchedObjects] count] > 0 ) {
//I know there are two statements here that can work individually from each other, but either of them would be a relevant matter.
[_tableView setAlpha:1.0];
[self.tableView setBackgroundColor:[UIColor purpleColor]];
}
else if ([[self.fetchedResultsController fetchedObjects] count] > 0 ) {
//I know there are two statements here that can work individually from each other, but either of them would be a relevant matter.
[_tableView setAlpha:1.0];
[self.tableView setBackgroundColor:[UIColor yellowColor]];
NSLog (@"");
}
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Change Color of TableView if Empty
if (![[self.fetchedResultsController fetchedObjects] count] > 0 ) {
//I know there are two statements here that can work individually from each other, but either of them would be a relevant matter.
[_tableView setAlpha:1.0];
[self.tableView setBackgroundColor:[UIColor purpleColor]];
}
else if ([[self.fetchedResultsController fetchedObjects] count] > 0 ) {
//I know there are two statements here that can work individually from each other, but either of them would be a relevant matter.
[_tableView setAlpha:1.0];
[self.tableView setBackgroundColor:[UIColor yellowColor]];
NSLog (@"");
}
}
-(IBAction)ReloadAction{
// Change Color of TableView if Empty
if (![[self.fetchedResultsController fetchedObjects] count] > 0 ) {
//I know there are two statements here that can work individually from each other, but either of them would be a relevant matter.
[_tableView setAlpha:1.0];
[self.tableView setBackgroundColor:[UIColor purpleColor]];
}
else if ([[self.fetchedResultsController fetchedObjects] count] > 0 ) {
//I know there are two statements here that can work individually from each other, but either of them would be a relevant matter.
[_tableView setAlpha:1.0];
[self.tableView setBackgroundColor:[UIColor yellowColor]];
NSLog (@"");
}
[_tableView reloadData];
//[_tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
}
Cheers Jeff
I figured it out
I added that if statement to where the + sign is defined and where the delete method is set in the code:-)
Thanks Anyway:-)