2016-04-05 7 views
0

Ich benutze UITableView im rechten Menü und ich kann keine Funktion für RESideMenu finden, die Tracks dieses Menü zeigt (oder wird angezeigt).Aktualisieren Sie Tabellenansicht Daten in RESideMenu, wenn es zeigt

fand ich zwei Funktionen:

- (void)sideMenu:(RESideMenu *)sideMenu willShowMenuViewController:(UIViewController *)menuViewController 

und

- (void)sideMenu:(RESideMenu *)sideMenu didShowMenuViewController:(UIViewController *)menuViewController 

aber sie tun nicht das, was ich brauche. Wie kann ich meine Tabellenansicht aktualisieren, wenn das Menü geöffnet wird?
Mein 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 
+0

exectly, was machst du da? –

+0

Ich erhalte aktualisierte Daten für die Tabellenansicht (die sich im rechten Menü befindet) von einem anderen View-Controller und wenn ich das rechte Menü öffne, muss ich meine Tabellenansicht neu laden. – Ookey

+0

Welche Art von aktualisierten Daten verwenden Sie? Array-Typ oder sonst? –

Antwort

0

up Stellt sich als Lösung ist sehr trivial:

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:YES]; 
    [_tableView reloadData]; 
} 
0

Check in DEMOLeftMenuViewController, für updateyour Tableview.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return 54; 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex 
{ 
    return 5; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *cellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
     cell.backgroundColor = [UIColor clearColor]; 
     cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:21]; 
     cell.textLabel.textColor = [UIColor whiteColor]; 
     cell.textLabel.highlightedTextColor = [UIColor lightGrayColor]; 
     cell.selectedBackgroundView = [[UIView alloc] init]; 
    } 

    NSArray *titles = @[@"Home", @"Calendar", @"Profile", @"Settings", @"Log Out"]; 
    NSArray *images = @[@"IconHome", @"IconCalendar", @"IconProfile", @"IconSettings", @"IconEmpty"]; 
    cell.textLabel.text = titles[indexPath.row]; 
    cell.imageView.image = [UIImage imageNamed:images[indexPath.row]]; 

    return cell; 
} 

// Delegierter //

- (void)sideMenu:(RESideMenu *)sideMenu willShowMenuViewController:(UIViewController *)menuViewController 
{ 
[reload tableview]; 

} 
+0

Es ist ein einfaches Beispiel für uitableview, ich weiß, wie man damit arbeitet. Und in der Demo-Tabellenansicht im Menü ist eine neuere Aktualisierung. Ich muss herausfinden, wie "wann das Menü angezeigt wird" angezeigt wird. – Ookey

+0

Ich versuchte das zu tun, bevor ich eine Frage stellte. Funktioniert nicht. – Ookey