Change initial Interface Controller for Apple Watch? - ios

Does anyone know how to do this in the ExtensionDelegate? Here's how I did it in the AppDelegate for iPhone
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStory" bundle:nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:#"2ndScreen"];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];

Related

App shows black screen in iOS

I am developing iOS app in which i have side menu with TabBar,
I have settled My sidemenu container viewController as IntitalViewController of my app.
Here is my code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
MFSideMenuContainerViewController *container = (MFSideMenuContainerViewController *)self.window.rootViewController;
UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:#"navigationController"];
UIViewController *leftSideMenuViewController = [storyboard instantiateViewControllerWithIdentifier:#"leftSideMenuViewController"];
[container setLeftMenuViewController:leftSideMenuViewController];
[container setCenterViewController:navigationController];
return YES;
}
Here is the Design of my Storybaord:
When i run my app i see a black screen with no error
Where i am making mistake, please help
Thanks in adavnnce !!
Give try to this (after seeing your code):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
self.window.rootViewController=[[MFSideMenuContainerViewController alloc]init];
// Override point for customization after application launch.
MFSideMenuContainerViewController *container = (MFSideMenuContainerViewController *)self.window.rootViewController;
UITabBarController *tabController = [storyboard instantiateViewControllerWithIdentifier:#"tabBarController"];
UIViewController *leftSideMenuViewController = [storyboard instantiateViewControllerWithIdentifier:#"leftSideMenuViewController"];
[container setLeftMenuViewController:leftSideMenuViewController];
[container setCenterViewController:tabController];
[self.window makeKeyAndVisible];
return YES;
}
Also give the respective id's to view controllers in storyboard ( for tabBar, navigation)
and don't forget to give root view controller for navigation
controller.

How to instantiate and push an (additional) storyboard into my app?

My app is mainly constructed without storyboards.
However, I have created just one for the registration of users.
This storyboard consists of a navigation controller containing 2 views controllers.
The first one is called "FirstVC", and the one "SecondVC" (this one would not be used for my question).
I am trying to push it in the AppDelegate.m file (trying various ways, see below) but my screen is always black.
attempt 1
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"FirstRegistration" bundle:nil];
FirstVC *fvc = [sb instantiateViewControllerWithIdentifier:#"FirstVC"];
UINavigationController *navController =(UINavigationController *)self.window.rootViewController;
[navController pushViewController:fvc animated:YES];
return YES;
}
attempt 2
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"FirstRegistration" bundle:nil];
FirstVC *fvc = [sb instantiateViewControllerWithIdentifier:#"FirstVC"];
self.window.rootViewController = fvc;
return YES;
}
Note : I've set the FirstVC scene to FirstVC in the identifier Custom Class section and also set the storyboard ID to FirstVC. However I have not touched to the NavigationController scene, should I just set the custom class to UINavigationController ?
can you try adding this line
[self.window makeKeyAndVisible];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"FirstRegistration" bundle:nil];
FirstVC *fvc = [sb instantiateViewControllerWithIdentifier:#"FirstVC"];
self.window.rootViewController = fvc;
[self.window makeKeyAndVisible]; //**Add this**
return YES;
}

Presenting ViewController from appDelegate

I need to show a ViewController from the appDelegate every time the app comes from the background in the applicationDidEnterBackground method.
The *securityCheck prompts the user for a passcode very much like the normal passcode in iOS. Once the passcode is validated I call dimissViewControllerAnimated inside the securityCheck and I am left with my blank UINavigationController, since the view was presented from the appDelegate I have no record of who presented the view, so I can't popToRootViewController.
My question is how can I properly dismiss the SecurityCheckViewController so that it shows the ViewController which the user was on before the app entered the background.
Here's my code:
This method is called inside AppDelegate.m
- (void)securityCheck {
SecurityCheckViewController *securityCheck = [[SecurityCheckViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:securityCheck];
[securityCheck presentedByAppDelegate:YES];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:navigationController];
[self.window makeKeyAndVisible];
}
Then inside the SecurityCheckViewController.m I have
- (void)unlockWasSuccessfulForPadLockScreenViewController:(ABPadLockScreenViewController *)padLockScreenViewController {
[self.appDelegate securityCheckDone];
[padLockScreenViewController dismissViewControllerAnimated:YES completion:nil];
NSLog(#"Sucsessfull Unlock");I'm
}
Present
- (void)securityCheck {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil];
SecurityCheckViewController *securityCheck = [storyboard instantiateViewControllerWithIdentifier:#"securityCheckView"];
[self.window.rootViewController presentViewController:securityCheck animated:NO completion:nil];
}
Dismiss
[self dismissViewControllerAnimated:YES completion:nil];
You can call this from application:didFinishLaunchingWithOptions
NOTE: All the storyBoard "initialViewControllers" tick box on the property inspector is turned off
UIStoryboard *storyboard =
[UIStoryboard storyboardWithName:#"Registration" bundle:nil];
RegisterViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"RegisterViewController"];
//this is key else you get a black screen
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];

I try to pushViewController but i cant

I try to push Viewcontroller it doesn't work.
AppDelegate.m (I import ViewController to use it as rootView)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
ViewController *view = [[ViewController alloc]init];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:view];
return YES;
}
Next is my Viewcontroller.m
-(void)goToView{
ViewController2 *view2 = [[ViewController2 alloc]initWithNibName:#"newView" bundle:nil];
[self.navigationController pushViewController:view2 animated:YES];
}
I got error message:
Cannot find executable for CFBundle 0x8f9bd80</Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.p‌​latform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/AccessibilityBundles‌​/CertUIFramework.axbundle>(not loaded)
2014-07-11 17:10:47.372 pushTest[2007:60b]***Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/home/Library/Application Support/iPhone Simulator/7.1/Applications/0D78CE53-F02B-467F-8250-8D2D3639A301/sta.app> (loaded)'with name 'newView'
This error can occure when you rename some files outside XCode. To solve it you can just remove the files from your project (Right Click - Delete and "Remove Reference") You re-import the files in your project and everything will be ok !
another choice
in your error code Could not load NIB in bundle means
ViewController2 *view2 = [[ViewController2 alloc]initWithNibName:#"newView" bundle:nil];
the Name newView does not match with bundle
just use this
ViewController2 *vc2 = [[ViewController2 alloc] init];
[self.navigationController pushViewController:vc2 animated:YES];
in your app delegate.m add the valid Navigation controller
try this Navigation Controller Push View Controller
try this:
in AppDelegate
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
RootViewController *rvc = [mainStoryboard instantiateViewControllerWithIdentifier:#"RootViewController"];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:rvc];
self.window.rootViewController = nc;
in your Storyboard add a new ViewController with the storyBoard Identifier: "RootViewController".
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
UINavigationController *navc = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navc;
[_window addSubview:navc.view];
[self.window makeKeyAndVisible];
return YES;
}
Hope it helps.

How to add navigation controller programmatically?

I use code below, but it is not loaded:
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
self.mapViewController = [storyboard instantiateViewControllerWithIdentifier:#"MapViewController"];
self.navigationController = [[UINavigationController alloc]initWithRootViewController:self];
self.navigationBar = [[UINavigationBar alloc]init];
[self.view addSubview:self.navigationBar];
[self.navigationController.navigationController pushViewController:self.mapViewController animated:YES];
try as below
UIViewController *bbp=[[UIViewController alloc]initWithNibName:#"UIViewController" bundle:nil];
UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:bbp];
// [self.navigationController presentModalViewController:passcodeNavigationController animated:YES];
[self.navigationController pushViewController:passcodeNavigationController animated:YES];
[passcodeNavigationController release];
Add this code to your AppDelegate.m in the didFinishLaunchingWithOptions function:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"YOUR_STORYBOARD_NAME" bundle:nil];
yourViewControllerClassName *vc = [sb instantiateViewControllerWithIdentifier:#"YOUR_VIEWCONTROLLER_ID"];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
yourViewControllerClassName is the .h and .m file name that is linked to your viewController.
YOUR_STORYBOARD_NAME is the name of your .storyboard file. For example, fill in Main if your .storyboard file is called Main.storyboard.
YOUR_VIEWCONTROLLER_ID is the ID for your veiwController. You can edit it in the Identity inspector.(See photo)
Hope this helps:)

Resources