Unable to call Lock Screen view controller from AppDelegate - ios

I have implemented the KKLockscreen view controller and is working well within the in-app settings controller. Able to set passcode and change them as well.
I am having problem to call he lock screen view from appdelegate. I have added delegate .h file and imported the view controller in .m file. still it's not calling the lockscreen. any help?
below is my code.
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if ([[KKPasscodeLock sharedLock] isPasscodeRequired]) {
KKPasscodeViewController *vc = [[KKPasscodeViewController alloc] initWithNibName:nil bundle:nil];
vc.mode = KKPasscodeModeEnter;
vc.delegate = self;
dispatch_async(dispatch_get_main_queue(),^ {
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.navigationBar.barStyle = UIBarStyleBlack;
nav.navigationBar.opaque = NO;
} else {
nav.navigationBar.tintColor = _navigationController.navigationBar.tintColor;
nav.navigationBar.translucent = _navigationController.navigationBar.translucent;
nav.navigationBar.opaque = _navigationController.navigationBar.opaque;
nav.navigationBar.barStyle = _navigationController.navigationBar.barStyle;
}
[_navigationController presentModalViewController:nav animated:NO];
});
}
}

i have checked it with my code and it is working ,ya but you have not give nib name here in this line and i have given may be that why it is not displaying your view.
KKPasscodeViewController *vc = [[KKPasscodeViewController alloc] initWithNibName:nil bundle:nil]
-(void)applicationDidBecomeActive:(UIApplication *)application {
RootViewController *vc = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
dispatch_async(dispatch_get_main_queue(),^ {
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.navigationBar.barStyle = UIBarStyleBlack;
nav.navigationBar.opaque = NO;
} else {
nav.navigationBar.tintColor = navigationController.navigationBar.tintColor;
nav.navigationBar.translucent = navigationController.navigationBar.translucent;
nav.navigationBar.opaque = navigationController.navigationBar.opaque;
nav.navigationBar.barStyle = navigationController.navigationBar.barStyle;
}
[navigationController presentModalViewController:nav animated:NO];
});
}

Related

IIViewDeckController is not working when push by navigation controller

Please help me in my project. I am using IIViewDeckController but its not working when pushed by view controller
Heres the hierarchy:
ViewController (Push)----> IIViewDeckController (with Left and centerview).
Here is my code when initialising the IIViewDeckController:
- (IIViewDeckController*)generateControllerStack{
self.navigationView = [[NavigationViewController alloc] initWithNibName:#"NavigationViewController" bundle:nil];
self.profileView = [[ProfileViewController alloc] initWithNibName:#"ProfileViewController" bundle:nil];
UINavigationController* navC = [[UINavigationController alloc] initWithRootViewController:self.profileView];
IIViewDeckController *deckView = [[IIViewDeckController alloc] initWithCenterViewController:navC leftViewController:self.navigationView rightViewController:nil];
deckView.leftSize = 50;
[deckView disablePanOverViewsOfClass:NSClassFromString(#"_UITableViewHeaderFooterContentView")];
return deckView;
}
then this is my code when I'm pushing IIViewDeckController using another ViewController
- (IBAction)signInAction:(id)sender {
IIViewDeckController *deckView = [[UIManager sharedItems] generateControllerStack];
[self.navigationController pushViewController:deckView animated:YES];
}
Thanks you very much guys :)
when I clicked sign in which is I will push my iiviewdeckcontroller with left and centre view this appears
Did you created it like this?
I am using it as root view controller. and it is working fine
UINavigationController* navController=(UINavigationController*)[[UIStoryboard storyboardWithName:#"Main" bundle: nil] instantiateViewControllerWithIdentifier:#"HomeViewController"];
SlideMenuViewController* slide=[[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"SlideMenuViewController"]; /
IIViewDeckController* deckController = [[IIViewDeckController alloc] initWithCenterViewController:navController
leftViewController:slide
rightViewController:nil
topViewController:nil
bottomViewController:nil];
float leftSize=self.window.frame.size.width - (88*self.window.frame.size.width)/320;
deckController.panningMode = IIViewDeckFullViewPanning;
deckController.leftSize =leftSize;
You can do like that.
//Appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController"
bundle:nil];
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:self.viewController];
self.window.rootViewController = navigation;
[self.window makeKeyAndVisible];
return YES;
}
import IIViewDeckController.h in ViewController.h then
- (IBAction)GoToNext:(id)sender
{
IIViewDeckController *objIIVC = [self.storyboard instantiateViewControllerWithIdentifier:#"Your VC's Identifier"];
[self.navigationController pushViewController:objIIVC animated:YES];
}
Here is my code
- (IIViewDeckController*)generateControllerStack{
self.navigationView = [[NavigationViewController alloc] initWithNibName:#"NavigationViewController" bundle:nil];
UIViewController *centerController = [[ProfileViewController alloc] initWithNibName:#"ProfileViewController" bundle:nil];
centerController = [[UINavigationController alloc] initWithRootViewController:centerController];
self.viewDeck = [[IIViewDeckController alloc] initWithCenterViewController:centerController leftViewController:self.navigationView rightViewController:nil topViewController:nil bottomViewController:nil];
self.viewDeck.leftSize = 50;
[self.viewDeck disablePanOverViewsOfClass:NSClassFromString(#"_UITableViewHeaderFooterContentView")];
return self.viewDeck;
}

MPMediaPickerController in UINavigationController

I would like to use an MPMediaPickerController in a navigation controller.
This does work:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MusicImport" bundle:[NSBundle mainBundle]];
UINavigationController *nav = [storyboard instantiateInitialViewController];
self.picker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAnyAudio];
self.picker.delegate = self;
self.picker.allowsPickingMultipleItems = NO;
self.picker.showsCloudItems = NO;
self.picker.view.frame = CGRectMake(0, 0, 1024, 768);
// add to dummy VC's view
[[nav.viewControllers[0] view] addSubview:self.picker.view];
nav.navigationBarHidden = YES;
nav.delegate = self;
self.mainNav = nav;
I then push my custom view controller when the user selects an item in the picker:
self.selectedItem = mediaItemCollection.items[0];
self.playbackViewController = [[PlaybackViewController alloc] initWithNibName:#"PlaybackViewController" bundle:[NSBundle mainBundle]];
self.playbackViewController.mediaItem = self.selectedItem;
self.playbackViewController.delegate = self;
self.mainNav.navigationBar.tintColor = self.picker.navigationController.navigationBar.tintColor;
self.mainNav.navigationBarHidden = NO;
[self.mainNav pushViewController:self.playbackViewController animated:YES];
so far, so good. only problem here is that the tintColor thing does not work.
the real problem is that when navigating back from my custom playback VC, the media picker does not become visible.
Even when I'm trying to add it back in the navigation controller's delegate method:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if(viewController == navigationController.viewControllers[0])
{
[viewController.view addSubview:self.picker.view];
navigationController.navigationBarHidden = YES;
}
}
alas, no dice.

PushView on PresentViewController iOS

I want to Push my viewController on PresentViewController
When i click on button initially i am loading PresentViewController, here is my code.
- (IBAction)JoinClicked:(id)sender{
JoinWithViewController *detail_view_controller = [[JoinWithViewController alloc] initWithNibName:#"JoinWithViewController" bundle:nil];
[self.view.window.rootViewController presentViewController:detail_view_controller
animated:YES
completion:NULL];
}
this works fine, but when i click on button which is there on PresentViewController on click i want to Push my view, but in does not pushes.
Please help, Thanks in advance.
JoinWithViewController *detail_view_controller = [[JoinWithViewController alloc] initWithNibName:#"JoinWithViewController" bundle:nil];
[self.navigationController pushViewController:detail_view_controller animated:YES];
Try like this to push viewController. If you use TabBar do like this in AppDelegate. If you create TabBar Drag and drop means leave that. Create TabBar Programatically like below.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UITabBarController *tabController = [[UITabBarController alloc]init];
self.viewController = [[CalculatorViewController alloc] initWithNibName:#"CalculatorViewController" bundle:nil];
UITabBarItem *tab_item1 = [[UITabBarItem alloc]init];
//tab_item1.title = #"Calculator";
tab_item1.image = [UIImage imageNamed:#"Calculator.png"];
[self.viewController setTabBarItem:tab_item1];
UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:self.viewController];
ShowPhoneViewController *phone = [[ShowPhoneViewController alloc]init];
UITabBarItem *tab_item2 = [[UITabBarItem alloc]init];
tab_item2.title = #"Latest Mobiles";
tab_item2.image = [UIImage imageNamed:#"Mobile.png"];
[phone setTabBarItem:tab_item2];
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:phone];
CurrencyConvertorViewController *currency = [[CurrencyConvertorViewController alloc]init];
UITabBarItem *tab_item3 = [[UITabBarItem alloc]init];
tab_item3.title = #"Units Convertor";
tab_item3.image = [UIImage imageNamed:#"Dollar.png"];
[currency setTabBarItem:tab_item3];
UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:currency];
SettingsPageViewController *setting = [[SettingsPageViewController alloc]init];
UITabBarItem *tab_item4 = [[UITabBarItem alloc]init];
tab_item4.title = #"Settings";
tab_item4.image = [UIImage imageNamed:#"Settings.png"];
[setting setTabBarItem:tab_item4];
UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:setting];
tabController.viewControllers = [NSArray arrayWithObjects:nav1, nav2, nav3, nav4, nil];
self.window.rootViewController = tabController;
[self.window makeKeyAndVisible];
return YES;
}
I hope you got now
pushviewcontroller is the feature of UINavigationController where you can push one viewcontroller on another vierw controller. Here you are using a single viewcontroller as a rootviewcontroller so either you must change your rootviewcontroller to UINavigationcontroller or you can use "addSubview method" to add new viewController on the current viewcontroller.
but the better option is to add uinavigationcontroller as a rootviewcontroller.
AppDelegate.m
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
FirstViewController *first = [[FirstViewController alloc]
initWithNibName:#"FirstViewController" bundle:nil];
UINavigationController *navController =[[UINavigationController alloc]
initWithRootViewController:first];
[self.window setRootViewController:navController];
}
Now when as you want to switch from FirstViewController to SecondViewController on button clicked than you have to use pushviewcontroller
FirstViewController.h
-(void) nextBtnPressed {
SecondViewController *second = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:second animated:TRUE];
}

iOS App with multiple view controllers

My current application on appDelegate loads a main.xib screen which only contains an two images background and logo. This screen behind code determines if the user is logged on the system if not it will show the login else it will show the dashboard.
The application has been created as a single view application, sample code of the appDelegate:
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
self.Main = [[vcMain alloc] initWithNibName:#"vcMain" bundle:nil];
self.window.rootViewController = self.Main;
[self.window makeKeyAndVisible];
}
else
{
self.MainiPad = [[vcMain_iPad alloc] initWithNibName:#"vcMain_iPad" bundle:nil];
self.window.rootViewController = self.MainiPad;
[self.window makeKeyAndVisible];
}
On the Main.m I have the following on the viewDidLoad:
if (islogged)
{
vcDashboard *vcDash = [[vcDashboard alloc] initWithNibName:#"vcDashboard" bundle:nil];
_ncMain = [[UINavigationController alloc] initWithRootViewController:vcDash];
_ncMain.navigationBar.barStyle = UIBarStyleBlackOpaque;
_ncMain.view.frame = self.view.bounds;
[self.view addSubview:_ncMain.view];
ViewActive = vDash;
}
else
{
vcLogin *login = [[vcLogin alloc] initWithNibName:#"vcLogin" bundle:nil];
login.modalPresentationStyle = UIModalPresentationFormSheet;
login.view.frame = self.view.bounds;
[self presentViewController:login animated:YES completion:nil];
}
There is a menu button available on the Dashboard that presents the user with a series of options to select another screen and when pressed it will activate the following method:
- (void)displayView:(NSString *)strView Notification:(NSNotification *)notification{
if(_ncMain)
{
[_ncMain.view removeFromSuperview];
_ncMain = nil;
}
if ([strView isEqual: #"Dashboard"])
{
vcDashboard *vcDash = [[vcDashboard alloc] initWithNibName:#"vcDashboard" bundle:nil];
_ncMain = [[UINavigationController alloc] initWithRootViewController:vcDash];
_ncMain.navigationBar.barStyle = UIBarStyleBlackOpaque;
_ncMain.view.frame = self.view.bounds;
[self.view addSubview:_ncMain.view];
ViewActive = vDash;
}
else if ([strView isEqual: #"Catalog"])
{
vcCatalog *vcCat = [[vcCatalog alloc] initWithNibName:#"vcCatalog" bundle:nil];
_ncMain = [[UINavigationController alloc] initWithRootViewController:vcCat];
_ncMain.navigationBar.barStyle = UIBarStyleBlackOpaque;
_ncMain.view.frame = self.view.bounds;
[self.view addSubview:_ncMain.view];
ViewActive = vCatalog;
}
else if ([strView isEqual: #"News"])
{
vcNews *vcNew = [[vcNews alloc] initWithNibName:#"vcNews" bundle:nil];
_ncMain = [[UINavigationController alloc] initWithRootViewController:vcNew];
_ncMain.navigationBar.barStyle = UIBarStyleBlackOpaque;
_ncMain.view.frame = self.view.bounds;
[self.view addSubview:_ncMain.view];
ViewActive = vNews;
}
}
My doubt here is I don't seem to know if this is the correct way of changing between screens when an option is selected from this menu and if is right to always addSubview to the principal screen. Don't know if using the navigationcontroller template is a solution. I'm concern of the memory consumed by the app when doing all of this, also I'm currently using ARC on the project.
I recommend you that avoid the addSubview method if possible. UiNAvigationController offer you a good way to handle different viewControllers. If you make addSubview the changeRotation event, for example, is not called. And when you make a pop the viewController is dealloced.
Good luck!

changin modalPresentationStyle after rotaiting

I need help in problem. I want to change modalPresentationStyle dynamicaly when it open, after rotating event.
I write this for create modalView
ZUITableViewController *ivc = [[ZUITableViewController alloc] init];
ivc.delegate = self;
_modalIsShowing = TRUE;
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:ivc];
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
nc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
nc.modalPresentationStyle = UIModalPresentationFormSheet;
}
else{
nc.modalPresentationStyle = UIModalPresentationFullScreen;
}
[self presentModalViewController:nc animated:YES];
[ivc release];
[nc release];
Scrap the if statement UIModalPresentationPageSheet behaves properly to start with.
ZUITableViewController *ivc = [[ZUITableViewController alloc] init];
ivc.delegate = self;
_modalIsShowing = TRUE;
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:ivc];
nc.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:nc animated:YES];
[ivc release];
[nc release];

Resources