FirstViewController doesn't work on removing the subview of SecondViewController - ios

First View Controller
I'm using a UIStoryBoard to allow the FirstViewController to add the view of second ViewController as a subview. On removing the sub view the
- (IBAction) btnMoveTo:(id)sender
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"Second"];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:vc animated:NO];
}
SecondViewController.m
-(void)viewDidLoad{
self.view.opaque = YES;
self.view.backgroundColor = [UIColor clearColor];
}
- (IBAction) withDraw:(id)sender{
[self.view removeWithZoomOutAnimation:2 option:nil];
}
When I access the withDraw Function, the view of the SecondViewController is removed and firstViewController is back. However when I use the button to access the - (IBAction) btnMoveTo:(id)sender function. It doesn't work. Nothing really happens. Any suggestions or help would be greatly appreciated.

Maybe you can try declare the *vc like this:
UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"Second"];

It worked
- (IBAction) withDraw:(id)sender{
[self.view removeWithZoomOViewControllerutAnimation:2 option:nil];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"First"];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:vc animated:NO];
}
I added another instance of the firstViewController by pointing to its identifier. So it brings back FirstViewController to the top.

Related

Navigation bar not appearing when pushing a controller from a presented ViewController

I have following code to present a UIViewController (named A) with UINavigationController.
I have kept navigation bar hidden as I do not want it on A by using following code
[self.navigationController.navigationBar setHidden:YES];
but when I push UIViewController named B I want the navigation bar to be displayed but it's not working even If set
self.navigationController?.setNavigationBarHidden(false, animated: false)
on UIViewController B. Can someone help me in this?
Here is the code to present UIViewController A
AppDelegate* delegate = [AppDelegate applicationDelegate];
UIStoryboard *story = [UIStoryboard storyboardWithName:STORYBOARD_MAIN bundle:nil];
SelectionViewController *tutorial = [story instantiateViewControllerWithIdentifier:#"SelectionViewController"];
tutorial.providesPresentationContextTransitionStyle = YES;
tutorial.definesPresentationContext = YES;
[tutorial setModalPresentationStyle:UIModalPresentationOverCurrentContext];
tutorial.delegate = self;
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:tutorial];
navController.modalPresentationStyle = UIModalPresentationFullScreen;
[navController.navigationBar setHidden:YES];
navController.providesPresentationContextTransitionStyle = YES;
navController.definesPresentationContext = YES;
[navController setModalPresentationStyle:UIModalPresentationOverCurrentContext];
[delegate.tabBarController presentViewController:navController animated:YES completion:NULL];
Here is the code to push UIViewController B
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"AppDetail" bundle:nil];
DetailViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"DetailViewController"];
[self.navigationController pushViewController:vc animated:YES];
[[self navigationController] setNavigationBarHidden:NO];
Additional information
UIViewController A is in different storyboard and B is in different
A's code is written in OBJ-C and B's code is in swift.

Three time ViewDidload method is calling

I am using Two storyboard one Main and another Dashboard.
After successfull response, I am loading LGSideMenu
Issue is DashboardViewController ViewDidLoad is calling 3 times.
-(void)loadDashboardController{
dispatch_async(dispatch_get_main_queue(), ^{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Dashboard" bundle:nil];
UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:#"NavigationController"];
DashboardViewController *mainViewController = [storyboard instantiateInitialViewController];
mainViewController.rootViewController = navigationController;
[mainViewController setupWithPresentationStyle:LGSideMenuPresentationStyleSlideAbove type:0];
UIWindow *window = [UIApplication sharedApplication].delegate.window;
window.rootViewController = mainViewController;
[UIView transitionWithView:window
duration:0.3
options:UIViewAnimationOptionTransitionCrossDissolve
animations:nil
completion:nil];
});
}
Is any one face this kind of issue?
you should set rootviewcontroller only once on window of your application. that's it. other view controller should be pushed on it or you should set as viewocontrollers of your navigation controller. so only set,
window.rootViewController = mainViewController;
//or
window.rootViewController = navigationcontroller;

Black screen after button click

I'm quite new to Objective-C. I want to go to another view controller but it shows me only the black screen after the button click. Is there something that I'm missing here?
Here is my code:
- (IBAction)measuring1stscan:(id)sender {
measuringscan *second = [[measuringscan alloc]initWithNibName:nil bundle:nil];
[self presentViewController:second animated:NO completion:NULL];
}
*measuringscan is the name for another view controller
viewConreoller default is no color, it is black. just add second.view.backgroundColor = [UIColor redColor];
- (IBAction)measuring1stscan:(id)sender {
measuringscan *second = [[measuringscan alloc] init];
second.view.backgroundColor = [UIColor redColor];
[self presentViewController:second animated:NO completion:NULL];
}
#rose is right try to give different color and then check.
Still you face same issue then try to run below code.
Embadded viewcontroller into navigation controller and give unique identifier to second viewcontroller.
- (IBAction)measuring1stscan:(id)sender
{
UIStoryboard *st = [UIStoryboard storyboardWithName:[NSString stringWithFormat:#"StoryboardWithName"] bundle:NULL];
measuringscan *second = [st instantiateViewControllerWithIdentifier:#"viewcontrollerIdentifier"];
[self.navigationController pushViewController:second animated:YES];
}
If you are using storyboard then use following
measuringscan *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"StoryboardIdentifier"];
[self presentViewController:controller animated:YES completion:nil];
or
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:[NSString stringWithFormat:#"StoryboardName"] bundle:nil];
measuringscan *controller = [storyboard instantiateViewControllerWithIdentifier:#"viewcontroller'sIdentifier"];
[self presentViewController:controller animated:YES completion:nil];
And if you aren't using storyboard instead you are using xib's then use following
measuringscan *controller = [[measuringscan alloc] initWithNibName:nil bundle:nil];
[self presentViewController:controller animated:YES completion:nil];
Points to remember (as said by #rmaddy)
Class name should be start with capital letter
Variable name should start with small letter
It is the naming convention that should be followed by a developer.
For more details click here

Push action for UIPopOverController

I created a pop over to view my settings like this,
if ([popoverController isPopoverVisible]) {
[popoverController
dismissPopoverAnimated:YES];
} else {
UIView* popoverView = [[UIView alloc]
initWithFrame:CGRectMake(566, 440, 0, 0)];
popoverView.backgroundColor = [UIColor blackColor];
controller1.contentSizeForViewInPopover = CGSizeMake(300, 115);
popoverController = [[UIPopoverController alloc]
initWithContentViewController:controller1];
[popoverController presentPopoverFromRect:popoverView.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
}
my push action code:
UIStoryboard *storyboard = [UIStoryboard
storyboardWithName:#"MainStoryboard"
bundle:nil];
UIViewController *controller = (UIViewController *)[storyboard
instantiateViewControllerWithIdentifier:#"PCBViewController"];
[self.navigationController
pushViewController:controller
animated:YES];
In my settings popover has some buttons. Those button is clicked, view controller open through push action but its not working.
My Question is: How to set push action for popover contents.
Your view is presented from popover thus self.navigationController will be nil.
Try this
UIStoryboard *storyboard = [UIStoryboard
storyboardWithName:#"MainStoryboard"
bundle:nil];
UIViewController *controller = (UIViewController *)[storyboard
instantiateViewControllerWithIdentifier:#"PCBViewController"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
[navigationController
pushViewController:controller
animated:YES];
you need to set up navigation controller for the view controller to allow navigation.
in your .h file
UINavigationController *navevent;
UIViewController *yourViewController
in .m file synthasize it and in view did load
navevent=[[UINavigationController alloc]initWithRootViewController:yourViewController];
yourViewController=[[UIViewController alloc]init];
then create your popover like this
yourViewController.view = yourView;
self.popoverController = [[UIPopoverController alloc]initWithContentViewController:navevent] ;
hope this help

presentViewController black screen or thread debug in IDE

I have seen the abundance of threads on this issue - I have tried all those solutions and they have failed. The build that ran, when I click the button it goes to the thread debugger page and I have no clue as to whats going on.
I need to go from a new class with its own .xib to the MainStoryboard where FirstViewController is.
- (IBAction)backToHome:(id)sender {
/*
FirstViewController *fvc = [[FirstViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:fvc animated:YES completion:nil];
*/
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
FirstViewController *fvc = [storyboard instantiateViewControllerWithIdentifier:#"FirstViewController"];
[self presentViewController:fvc animated:YES completion:nil];
}
When using the commented code it goes to a black screen
FirstViewController *fvc = [[FirstViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:fvc animated:YES completion:nil];
Here initWithNibName:nil causes black screen as it is not able to load nib.
i think you should add name
FirstViewController *fvc = [[FirstViewController alloc] initWithNibName:#"somethinghere" bundle:nil]; [self presentViewController:fvc animated:YES completion:nil];

Resources