I'm using UITableView
in right menu and I can't find any function for RESideMenu
which tracks that menu is showing (or will show).
I found two functions :
- (void)sideMenu:(RESideMenu *)sideMenu willShowMenuViewController:(UIViewController *)menuViewController
and
- (void)sideMenu:(RESideMenu *)sideMenu didShowMenuViewController:(UIViewController *)menuViewController
But they don't do what I need.
How can I update my tableview when menu opens?
My code:
RightMenuViewController.h
#import <UIKit/UIKit.h>
#import "DataAPI.h"
#import "RESideMenu.h"
#import "RightMenuTableViewCell.h"
@interface RightMenuViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, RESideMenuDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end
RightMenuViewController.m
#import "RightMenuViewController.h"
@interface RightMenuViewController ()
@end
@implementation RightMenuViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithRed:[[[UICustomization sharedInstance].backgroundColour objectForKey:@"r"] floatValue]/225.0f green:[[[UICustomization sharedInstance].backgroundColour objectForKey:@"g"] floatValue]/225.0f blue:[[[UICustomization sharedInstance].backgroundColour objectForKey:@"b"] floatValue]/225.0f alpha:1.0f];
_tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
if ([[UICustomization sharedInstance].tableBackgroundColour count])
_tableView.backgroundColor = [UIColor colorWithRed:[[[UICustomization sharedInstance].tableBackgroundColour objectForKey:@"r"] floatValue]/225.0f green:[[[UICustomization sharedInstance].tableBackgroundColour objectForKey:@"g"] floatValue]/225.0f blue:[[[UICustomization sharedInstance].tableBackgroundColour objectForKey:@"b"] floatValue]/225.0f alpha:1.0f];
else
_tableView.backgroundColor = [UIColor clearColor];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:YES];
NSLog(@"push notifications: %@", [DataAPI sharedInstance].pushNotifications);
}
- (void)sideMenu:(RESideMenu *)sideMenu willShowMenuViewController:(UIViewController *)menuViewController {
[_tableView reloadData];
NSLog(@"push notifications: %@", [DataAPI sharedInstance].pushNotifications);
}
- (void)sideMenu:(RESideMenu *)sideMenu didShowMenuViewController:(UIViewController *)menuViewController {
[_tableView reloadData];
NSLog(@"push notifications: %@", [DataAPI sharedInstance].pushNotifications);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (![[DataAPI sharedInstance].pushNotifications count])
return 1;
else
return [[[DataAPI sharedInstance].pushNotifications objectForKey:@"data"] count];
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([[DataAPI sharedInstance].pushNotifications count]) {
[DataAPI sharedInstance].orderNavButtonsOn = YES;
[[ConnectionService instance]get_single_order:[UserAuth instance].username password:[UserAuth instance].password orderID:[[[[DataAPI sharedInstance].pushNotifications objectForKey:@"data"] objectAtIndex:indexPath.section] objectForKey:@"objectID"]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveConnectionData:)
name:@"SingleOrderDataReceived"
object:nil];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 10.;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [[UIView alloc] init];
headerView.backgroundColor = [UIColor clearColor];
return headerView;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return nil;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (![[DataAPI sharedInstance].pushNotifications count]) {
static NSString *MyIdentifier = @"Identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
cell.layer.borderWidth = 1.0f;
cell.layer.borderColor = [UIColor colorWithRed:[[[UICustomization sharedInstance].cellBorderColour objectForKey:@"r"] floatValue]/225.0f green:[[[UICustomization sharedInstance].cellBorderColour objectForKey:@"g"] floatValue]/225.0f blue:[[[UICustomization sharedInstance].cellBorderColour objectForKey:@"b"] floatValue]/225.0f alpha:1.0f].CGColor;
cell.textLabel.text = NSLocalizedString(@"no_notifications", nil);
cell.textLabel.textColor = [UIColor colorWithRed:[[[UICustomization sharedInstance].primaryTextColour objectForKey:@"r"] floatValue]/225.0f green:[[[UICustomization sharedInstance].primaryTextColour objectForKey:@"g"] floatValue]/225.0f blue:[[[UICustomization sharedInstance].primaryTextColour objectForKey:@"b"] floatValue]/225.0f alpha:1.0f];
cell.userInteractionEnabled = NO;
return cell;
} else {
static NSString *MyIdentifier = @"rightMenuCell";
RightMenuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
cell = [[RightMenuTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
cell.dateLabel.text = [[[[DataAPI sharedInstance].pushNotifications objectForKey:@"data"] objectAtIndex:indexPath.section] objectForKey:@"date_time"];
cell.timeLabel.text = [[[[DataAPI sharedInstance].pushNotifications objectForKey:@"data"] objectAtIndex:indexPath.section] objectForKey:@"ago"];
cell.statusLabel.text = [[[[DataAPI sharedInstance].pushNotifications objectForKey:@"data"] objectAtIndex:indexPath.section] objectForKey:@"pushed_message"];
return cell;
}
return 0;
}
- (void)receiveConnectionData:(NSNotification *) notification {
if ([[notification name] isEqualToString:@"SingleOrderDataReceived"]) {
[DataAPI sharedInstance].singleOrder = notification.object;
dispatch_sync(dispatch_get_main_queue(), ^{
[self goToViewWithIdentifier:@"toOrder"];
});
}
}
- (void)goToViewWithIdentifier:(NSString *)identifier {
[self connectionCheck];
[self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[self.storyboard instantiateViewControllerWithIdentifier:identifier]]
animated:YES];
[self.sideMenuViewController hideMenuViewController];
}
- (void)connectionCheck {
if ([[ConnectionService instance]checkConnectivity] == NO) {
UIAlertController * alert = [UIAlertController
alertControllerWithTitle:NSLocalizedString(@"internet_connection_error_title", nil)
message:NSLocalizedString(@"internet_connection_error_message", nil)
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* quitButton = [UIAlertAction
actionWithTitle:NSLocalizedString(@"internet_connection_error_cancel_button", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
exit(0);
}];
UIAlertAction* tryAgainButton = [UIAlertAction
actionWithTitle:NSLocalizedString(@"internet_connection_error_try_again_button", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[self connectionCheck];
}];
[alert addAction:quitButton];
[alert addAction:tryAgainButton];
[self presentViewController:alert animated:YES completion:nil];
}
}
@end
Turns up than solution is very trivial:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:YES];
[_tableView reloadData];
}