Black screen on slide-out menu VC - ios

I'm using the SWViewController Library. When implementing the library, my frontViewController shows up but my rearViewController is black. I don't know what's causing this issue and could use some help with it. The app is entirely programmed in Objective C. There is no swift and no storyboards with this app.
Here is my code for rearViewController.h:
#import <UIKit/UIKit.h>
#interface RearViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
#property (nonatomic, retain) IBOutlet UITableView *rearTableView;
#end
rearViewController.m:
#import "RearViewController.h"
#import "SWRevealViewController.h"
#interface RearViewController()
{
NSInteger _presentedRow;
}
#end
#implementation RearViewController
#synthesize rearTableView = _rearTableView;
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = NSLocalizedString(#"Rear View", nil);
}
my code for appDelegate.h:
#class SWRevealViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) TARootViewController *rootViewController;
#property (strong, nonatomic) SWRevealViewController *viewController;
#property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
#property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
#property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
#end
and my code for appDelegate.m:
#import "AppDelegate.h"
#import "SWRevealViewController.h"
#import "RearViewController.h"
#interface AppDelegate()<SWRevealViewControllerDelegate>
#end
#implementation AppDelegate
#synthesize window = _window;
#synthesize viewController = _viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
RearViewController *rearViewController = [[RearViewController alloc] init];
TARootViewController *frontViewController = [[TARootViewController alloc] init];
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearViewController frontViewController:frontViewController];
revealController.delegate = self;
self.window.rootViewController = revealController;
[self.window makeKeyAndVisible];
if (self.rootViewController.activeViewController == nil) {
[[TAActiveUserManager sharedManager] startOrResumeAppSession];
}
// Register device for push notifications
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
return YES;
}
there is more here but it's not relevant to initializing the viewcontrollers

I asked this on reddit as well, and here is the thread that answered my question.
It turns out that black is the default viewController color for SWRevealViewController - just because it's black doesn't mean that it's not loading properly.

This has had happened to me before. The default background color for view controllers is clear. make sure you have your background or at least your window's background color set. In AppDelegate.m:
self.window.backgroundColor = [UIColor whiteColor];
Also, I'm assuming you want a navigation controller in their since your setting a view controllers self.title property. The title will show up in the Navigation bar when that particular view controller is on top of the stack. It is simple to imbed your view controller into a navigationController. Replace this with the line where you set your rootViewController.
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:revealController];

Related

How to Add Login to my iOS PDF reader App?

So I'm trying to add a login to my existing app. My App has two Storyboards one for iPhone and another for iPad. I added a login view set to rootViewController but I can't seem to load my UITabBarController correctly.Normally a PDF should load. I add the login that then segs to the UITabBarController but nothing is loaded its just an empty storyboard. I'm not loading it(the tab bar and document) properly or something. I'm a noob any and all help appreciated.
App Delegate file:
#interface AppDelegate () <UITabBarControllerDelegate>
#property (nonatomic, strong) PDFDocumentStore *documentStore;
#property (nonatomic, strong) DocumentListViewController *documentsViewController;
#property (nonatomic, strong) DocumentListViewController *recentViewController;
#property (nonatomic, assign) BOOL launchingWithURL;
#property (nonatomic, assign) BOOL addSkipBackupAttributeToItemAtURL;
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self migrateIfNeeded];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
UIViewController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:#"Login"];
[[UIApplication sharedApplication].keyWindow setRootViewController:rootViewController];
self.documentStore = PDFDocumentStore.new;
[self.documentStore.rootFolder load];
UITabBarController *tabBar = (UITabBarController *)[[self window] rootViewController];
tabBar.delegate = self;
self.documentsViewController = (DocumentListViewController *)[tabBar.viewControllers[0] topViewController];
FolderDocumentListViewModel *folderModel =
[[FolderDocumentListViewModel alloc] initWithFolder:self.documentStore.rootFolder];
self.documentsViewController.viewModel = folderModel;
[self.documentsViewController view];
self.recentViewController = (DocumentListViewController *)[tabBar.viewControllers[1] topViewController];
RecentDocumentListViewModel *recentModel =
[[RecentDocumentListViewModel alloc] initWithDocumentList:self.documentStore.documentList];
self.recentViewController.viewModel = recentModel;
NSString *pdf = #"2016 Product Handbook";
NSString *toPath = [[[NSFileManager grt_documentsPath]
stringByAppendingPathComponent:pdf]
stringByAppendingPathExtension:#"pdf"];
[self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:toPath]];
NSURL *URL = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
if (URL) {
self.launchingWithURL = YES;
}
return YES;
}
Create a UITabBarController in your `AppDelegate.h' file.
#property (strong, nonatomic) UITabBarController *tabBarController;
-(void)userDidLoginSuccessfully;
And then declare a public function in AppDelegate.h file. (Lets say userDidLoginSuccessfully is my function in this case).
In Your AppDelegate.m file write this function.
-(void)userDidLoginSuccessfully{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
self.tabBarController = [[UITabBarController alloc]init]
self.tabBarController = [storyboard instantiateViewControllerWithIdentifier:#"MyTabBarController"];
[self.window setRootViewController:self.TabBarController];
}
Then in you LoginViewController where you check the success of login within if-else block just write these lines.
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate userDidLoginSuccessfully];
Do you want to load UITabBarController after success of login. Right?

Xib doesn't load as expected

It has been a while since I created a project from scratch. Back then in XCode 4 / 5 the developer was given the choice between storyboard or Xib to get the project started. In Xcode 6 though every template is forced to get started as StoryBoard.
I have removed the story board. Then I have opened info.plist in Supporting files and set Main storyboard file base name : Main to Main storyboard file base name: <blank>.
Then I created a basic testViewController with Xib (same name).
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
#end
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
testViewController *firstViewController = [[testViewController alloc] initWithNibName:nil bundle:nil];
self.navigationController.viewControllers = [NSArray arrayWithObject:firstViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
And this still shows me a black view controller. I checked the xib file, the File owner is set to the view controller and the view delegate is also set.
What am I missing please?
change these two things:
#property (nonatomic, retain) IBOutlet UIWindow *window;
testViewController *firstViewController = [[testViewController alloc] initWithNibName:nil bundle:nil];
To this, and add this code, with the real name or you xib file:
#property (nonatomic, retain) UIWindow *window; // Are you using ARC?
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// I think your xib files is testViewcontroller.xib, if not change it.
testViewController *firstViewController = [[testViewController alloc] initWithNibName:testViewController.xib bundle:nil];
// change this also
self.navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;

NSInternalInconsistencyException error

I am having issues switching between view controllers.
My md360AppDelegate.h header looks like this
#import <UIKit/UIKit.h>
#class md360ViewController;
#interface md360AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) md360ViewController *viewController;
#property (strong, nonatomic) UINavigationController *navigationController;
#end
and my md360AppDelegate.m implementation looks like this.
#import "md360AppDelegate.h"
#import "md360ViewController.h"
#implementation md360AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[md360ViewController alloc] initWithNibName:#"md360ViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.navigationController setNavigationBarHidden:YES animated:YES];
[self.window setRootViewController:self.navigationController];
[self.window makeKeyAndVisible];
return YES;
}
#end
i am creating an instance of UINavigationController and storing it in navigationController property of this class.
I want to change the ViewController when a user click on a button in md360ViewController.
My md360ViewController.h looks like this.
#interface md360ViewController : UIViewController
#property IBOutlet UIButton *homePathwayBtn;
#property IBOutlet UIButton *homeDiseaseBtn;
#property IBOutlet UIButton *homePipelineBtn;
- (IBAction)homeButton:(id)sender;
#end
and my implementation looks something like
#import "md360ViewController.h"
#import "md360AppDelegate.h"
#import "pipeViewDisease.h"
#import <QuartzCore/QuartzCore.h>
- (IBAction)homeButton:(id)sender {
UIViewController *pipeViewDisease = [[UIViewController alloc] initWithNibName:#"pipeViewDiease" bundle:nil];
[self.navigationController pushViewController:pipeViewDisease animated:YES];
}
and when i click on UIButton the application crash with following message.
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'Could not load NIB in
bundle: 'NSBundle
(loaded)' with name 'pipeViewDiease''
what could be the issue?
Probably just a misspelled NIB name:
initWithNibName:#"pipeViewDiease"
should be:
initWithNibName:#"pipeViewDisease"
^
Unless it's a spelling mistake (should be pipeViewDisease), this error usually occurs when files are re-named outside of the xCode environment.
To fix this:
remove the file in question from the project
re-import the files to your project.

Basic error in iPad application launch

I have a file named MMAppDelegate.m:
#import "MMAppDelegate.h"
#implementation MMAppDelegate
#synthesize window;
#synthesize viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
viewController = [[MainViewController alloc] init];
[window addSubview:viewController.view];
// Override point for customization after application launch.
[window makeKeyAndVisible];
return YES;
}
//and more standard methods
MMAppDelegate.h:
#import <UIKit/UIKit.h>
#import "MainViewController.h"
#interface MMAppDelegate : UIResponder <UIApplicationDelegate> {
UIWindow *window;
MainViewController *viewController;
}
#property (nonatomic, retain) UIWindow *window;
#property (nonatomic, retain) MainViewController *viewController;
#end
MainViewController.m:
#import "MainViewController.h"
#implementation MainViewController
- (void)viewDidLoad {
NSLog(#"view did load main view controller");
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
}
#end
And yet when I run the program, I get a black screen, and the output:
2012-02-12 15:44:48.160 MoreMost[44076:f803] view did load main view controller
2012-02-12 15:44:48.163 MoreMost[44076:f803] Applications are expected to have a root view controller at the end of application launch
What is the problem?
Change this line:
[window addSubview:viewController.view];
to this:
window.rootViewController = viewController;
And you'll need to create the window, like this:
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
You don't need/want to add the view controller's view as a subview. You want to make your controller the root view controller and iOS will take care of the rest:
window.rootViewController = viewController;
That is, as of iOS 4. (Not sure the answer if you're going back earlier than that.)
You also need to create the window before you use it. Something like
window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
Not sure if you aren't or if you just didn't show it ...

Why does my iOS app crash when trying presentModalViewController?

I've been banging my head against this all day, it seems like something simple but I can't figure it out.
I've got an iOS app that I created using the "View-based Application" template in XCode. Here is essentially the code I have:
AppDelegate.h:
#import <UIKit/UIKit.h>
#interface AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
MainViewController *viewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet MainViewController *viewController;
#end
AppDelegate.m:
#import "AppDelegate.h"
#import "MainViewController.h"
#implementation AppDelegate
#synthesize window, viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
#end
MainViewController.h:
#import <UIKit/UIKit.h>
#interface MainViewController : UIViewController {
}
-(IBAction) button:(id)sender;
#end
MainViewController.m:
#import "MainViewController.h"
#import "ModalViewController.h"
#implementation MainViewController
...
-(IBAction) button:(id)sender {
ModalViewController *mvc = [[[ModalViewController alloc] initWithNibName:NSStringFromClass([ModalViewController class]) bundle:nil] autorelease];
[self presentModalViewController:mvc animated:YES];
}
#end
There's nothing of interest in the ModalViewController.
So the modal view should display when the button is pressed. When I press the button, it hangs for a second then crashes back to the home screen with no error message.
I am stumped, please show me what I'm doing wrong!
There's nothing of interest in the ModalViewController.
Although there may not be anything of interest, there could still be something causing the problem.
Does your View Controller override the function loadView?
A problem that has got me a few times is if you don't call [super loadView]; first in your overriden loadView method. Not doing this causes a crash when moving into that View Controller.
Good luck in trying to solve this one!
N

Resources