3

ストーリーボードを使用せずにプロジェクトに SWRevealViewController を実装しようとしています。可能だと思いますが、残念ながら失敗しました。ナビゲーション バーのボタンは、彼に定義されている「revealToggle」アクションを実行しません。したがって、NavigationTableViewController は表示されません。理由がわかりません... この問題の解決策を数時間探しました。誰でも助けていただければ幸いです。

#import "ContentViewController.h"
#import "NavigationTableViewController.h"

@interface ContentViewController()<SWRevealViewControllerDelegate>

@end

@implementation ContentViewController

- (void)viewDidLoad {
[super viewDidLoad];

// Do any additional setup after loading the view from its nib.
//[self.navigationItem setHidesBackButton:YES animated:YES];

UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;

ContentViewController *frontViewController = self;
NavigationTableViewController *rearViewController = [[NavigationTableViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearViewController frontViewController:frontNavigationController];
revealController.delegate = self;

[revealController panGestureRecognizer];
[revealController tapGestureRecognizer];


self.viewController = revealController;
self.window.rootViewController = self.viewController;

UIBarButtonItem *revealButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"reveal-icon.png"]
                                                                     style:UIBarButtonItemStyleBordered target:revealController action:@selector(revealToggle:)];
self.navigationItem.leftBarButtonItem = revealButtonItem;

}
4

1 に答える 1

2

私はついに私の問題を解決することができました。John Lluch の例によると、コードを変更しました。ストーリーボードを使用しないソリューションは次のとおりです。

AppDelegate.h

#import <UIKit/UIKit.h>
#import "SplashScreenController.h"
#import "SWRevealViewController.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navigationController;
@property (strong, nonatomic) SplashScreenController *viewController;
@property (strong, nonatomic) SWRevealViewController *revealController;

@end

AppDelegate.m

#import "AppDelegate.h"
#import "ContentViewController.h"
#import "NavigationTableViewController.h"


@interface AppDelegate()<SWRevealViewControllerDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    SplashScreenController *frontViewController = [[SplashScreenController alloc] initWithNibName:@"SplashScreenController" bundle:nil];
    NavigationTableViewController *rearViewController = [[NavigationTableViewController alloc] init];
    UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
    SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearViewController frontViewController:frontNavigationController];

    revealController.delegate = self;

    self.window.rootViewController = revealController;

    [self.window makeKeyAndVisible];

    return YES;

}

ContentViewController.h

#import <UIKit/UIKit.h>

@interface ContentViewController : UIViewController
@end

ContentViewController.m

#import "ContentViewController.h"
#import "SWRevealViewController.h"
#import "NavigationTableViewController.h"
#import <sqlite3.h>

@interface ContentViewController()<SWRevealViewControllerDelegate>

@end

@implementation ContentViewController



- (void)viewDidLoad {

    [super viewDidLoad];

    SWRevealViewController *revealController = [self revealViewController];
    [revealController panGestureRecognizer];
    [revealController tapGestureRecognizer];

    UIBarButtonItem *revealButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"reveal-icon.png"] style:UIBarButtonItemStyleBordered target:revealController action:@selector(revealToggle:)];

    self.navigationItem.leftBarButtonItem = revealButtonItem;

}
于 2014-11-26T08:26:27.440 に答える