2016-04-05 3 views
0

私はUITableViewを使用しています。メニューが表示されている(または表示されている)RESideMenuの機能が見つかりません。RESIDEMenuでテーブルビューのデータを更新すると、

私は2つの機能が見つかりました:

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

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

をしかし、彼らは私が必要なものを行いません。 メニューが開いたときにテーブルビューを更新するにはどうすればよいですか?
マイコード:
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

? –

+0

私は別のビューコントローラからテーブルビュー(右メニューの内側にあります)の更新データを受け取りました。右のメニューを開くと、テーブルビューをリロードする必要があります。 – Ookey

+0

あなたはどのタイプの更新データを使用していますか?配列型かどうか? –

答えて

0

は解決策は非常に簡単ですよりも、ターンアップ//:あなたは何をしているexectly

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

updateyourのテーブルビューのためのDEMOLeftMenuViewControllerでチェック。

- (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; 
} 

//デリゲート

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

} 
+0

これは、uitableviewの簡単な例です。私はそれを操作する方法を知っています。そして、メニューのデモでは、テーブルビューは新しいアップデートです。私は "メニューが表示される/表示される時"を追跡する方法を理解する必要があります。 – Ookey

+0

私は質問をする前にそれをやろうとしました。働いていない。 – Ookey

関連する問題