Reputation: 33
I have successfully implemented SWRevealViewController Class in my project.
https://github.com/John-Lluch/SWRevealViewController
But when I use revealToggle: method as my left bar button item action, it shows a complete black screen. The View is completely black. But when I use rightRevealToggle: method, the view loads normally.
I'm including the code of AppDelegate.h,AppDelegate.m and Main view.
Slide out view is an empty view now. Just background colour changed.
Check it and let me know what is wrong.
Here is the screenshot of the project in simulator
http://i57.tinypic.com/mljpe9.png
// AppDelegate.h
// IndianBloodBank
//
// Created by Roshith Balendran on 8/5/14.
// Copyright (c) 2014 Olympus. All rights reserved.
//
#import <UIKit/UIKit.h>
@class SWRevealViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) SWRevealViewController *splitMenu;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
@end
// AppDelegate.m
// IndianBloodBank
//
// Created by Roshith Balendran on 8/5/14.
// Copyright (c) 2014 Olympus. All rights reserved.
//
#import "AppDelegate.h"
#import "SWRevealViewController.h"
#import "HomePageViewController.h"
#import "SlideOutMenuViewController.h"
#import "SearchViewController.h"
#import "SearchViewController.h"
#import "AboutUsViewController.h"
#import "SponsorsViewController.h"
#import "HowToDonateViewController.h"
#import "EmergencyViewController.h"
@interface AppDelegate()<SWRevealViewControllerDelegate>
@end
@implementation AppDelegate
@synthesize splitMenu,window;
@synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window = window;
HomePageViewController *HPVC = [[HomePageViewController alloc]init];
SlideOutMenuViewController *SOMVC = SOMVC = [[SlideOutMenuViewController alloc]init];
UINavigationController *frontNavigationController = [[UINavigationController alloc]initWithRootViewController:HPVC];
UINavigationController *rearNavigationController = [[UINavigationController alloc]initWithRootViewController:SOMVC];
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.125 green:0.122 blue:0.133 alpha:1]];
SWRevealViewController *revealController= [[SWRevealViewController alloc]initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
revealController.rearViewRevealWidth = 120;
revealController.rearViewRevealOverdraw = 120;
revealController.bounceBackOnOverdraw = NO;
revealController.stableDragOnOverdraw = YES;
[revealController setFrontViewPosition:FrontViewPositionLeft];
revealController.delegate=self;
revealController.rightViewController = SOMVC;
self.splitMenu = revealController;
self.window.rootViewController = self.splitMenu;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
// HomePageViewController.m
// IndianBloodBank
//
// Created by Roshith Balendran on 8/5/14.
// Copyright (c) 2014 Olympus. All rights reserved.
//
#import "HomePageViewController.h"
#import "SWRevealViewController.h"
#import "AboutUsViewController.h"
#import "SponsorsViewController.h"
#import "HowToDonateViewController.h"
#import "SearchViewController.h"
@interface HomePageViewController ()
@end
@implementation HomePageViewController
@synthesize btn1SearchBlood,btn2DonateNow;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.navigationController.navigationBar.translucent=NO;
SWRevealViewController *revealViewController = [self revealViewController];
[revealViewController panGestureRecognizer];
[revealViewController tapGestureRecognizer];
UIView* MenuButtonView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 25, 20)];
UIButton* MenuButton=[UIButton buttonWithType:UIButtonTypeSystem];
MenuButton.frame=MenuButtonView.frame;
[MenuButton setImage:[UIImage imageNamed:@"v1_menu-icon"] forState:UIControlStateNormal];
MenuButton.tintColor=[UIColor grayColor];
MenuButton.autoresizesSubviews=YES;
MenuButton.autoresizingMask=UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;
[MenuButton addTarget:revealViewController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];
[MenuButtonView addSubview:MenuButton];
UIBarButtonItem *Menu=[[UIBarButtonItem alloc]initWithCustomView:MenuButtonView];
self.navigationItem.leftBarButtonItem=Menu;
}
Upvotes: 0
Views: 1106
Reputation: 33
I have found a solution to my problem...
My trainer helped me to solve it.
Here is the edited code.
Thank you for all the help.
// AppDelegate.h
// IndianBloodBank
//
// Created by Roshith Balendran on 8/5/14.
// Copyright (c) 2014 Olympus. All rights reserved.
//
#import <UIKit/UIKit.h>
@class SWRevealViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) SWRevealViewController *splitMenu;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
@end
// AppDelegate.m
// IndianBloodBank
//
// Created by Roshith Balendran on 8/5/14.
// Copyright (c) 2014 Olympus. All rights reserved.
//
#import "AppDelegate.h"
#import "SWRevealViewController.h"
#import "HomePageViewController.h"
#import "SlideOutMenuViewController.h"
#import "SearchViewController.h"
#import "SearchViewController.h"
#import "AboutUsViewController.h"
#import "SponsorsViewController.h"
#import "HowToDonateViewController.h"
#import "EmergencyViewController.h"
@interface AppDelegate()<SWRevealViewControllerDelegate>
@end
@implementation AppDelegate
@synthesize splitMenu,window;
@synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
// self.window = window;
HomePageViewController *HPVC = [[HomePageViewController alloc]initWithNibName:@"HomePageViewController" bundle:nil];
SlideOutMenuViewController *SOMVC ;
SOMVC = [[SlideOutMenuViewController alloc]init];
UINavigationController *frontNavigationController = [[UINavigationController alloc]initWithRootViewController:HPVC];
// UINavigationController *rearNavigationController = [[UINavigationController alloc]initWithRootViewController:SOMVC];
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.078 green:0.09 blue:0.078 alpha:1]];
splitMenu= [[SWRevealViewController alloc]initWithRearViewController:SOMVC frontViewController:frontNavigationController];
splitMenu.rearViewRevealWidth = 120;
splitMenu.rearViewRevealOverdraw = 120;
splitMenu.bounceBackOnOverdraw = NO;
splitMenu.stableDragOnOverdraw = YES;
[splitMenu setFrontViewPosition:FrontViewPositionLeft];
splitMenu.delegate=self;
splitMenu.rightViewController = SOMVC;
self.window.rootViewController = splitMenu;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
// HomePageViewController.m
// IndianBloodBank
//
// Created by Roshith Balendran on 8/5/14.
// Copyright (c) 2014 Olympus. All rights reserved.
//
#import "HomePageViewController.h"
#import "SWRevealViewController.h"
#import "AboutUsViewController.h"
#import "SponsorsViewController.h"
#import "HowToDonateViewController.h"
#import "SearchViewController.h"
@interface HomePageViewController ()
@end
@implementation HomePageViewController
{
SWRevealViewController *slideController;
}
@synthesize btn1SearchBlood,btn2DonateNow;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.navigationController.navigationBar.translucent=NO;
slideController = [self revealViewController];
//[revealViewController panGestureRecognizer];
// [revealViewController tapGestureRecognizer];
UIView* MenuButtonView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 25, 20)];
UIButton* MenuButton=[UIButton buttonWithType:UIButtonTypeSystem];
MenuButton.frame=MenuButtonView.frame;
[MenuButton setImage:[UIImage imageNamed:@"v1_menu-icon"] forState:UIControlStateNormal];
MenuButton.tintColor=[UIColor grayColor];
MenuButton.autoresizesSubviews=YES;
MenuButton.autoresizingMask=UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;
[MenuButton addTarget:slideController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];
[MenuButtonView addSubview:MenuButton];
UIBarButtonItem *Menu=[[UIBarButtonItem alloc]initWithCustomView:MenuButtonView];
self.navigationItem.leftBarButtonItem=Menu;
}
Upvotes: 1