首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SWRevealViewController不切换

SWRevealViewController不切换
EN

Stack Overflow用户
提问于 2014-11-25 13:58:56
回答 1查看 838关注 0票数 3

我试图在不使用故事板的项目中实现SWRevealViewController。我认为这是可能的,但不幸的是我失败了。导航栏中的按钮不执行对其定义的"revealToggle“操作。所以NavigationTableViewController从来没有显示过。我不明白为什么..。我找了好几个小时来解决这个问题。任何帮助的人都将不胜感激。

代码语言:javascript
复制
#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;

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-26 08:26:27

我终于解决了我的问题。根据约翰·卢卡的例子,我修改了我的代码。以下是不使用故事板的解决方案:

AppDelegate.h

代码语言:javascript
复制
#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

代码语言:javascript
复制
#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

代码语言:javascript
复制
#import <UIKit/UIKit.h>

@interface ContentViewController : UIViewController
@end

ContentViewController.m

代码语言:javascript
复制
#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;

}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27128686

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档