directly segueing between different detail view controllers - iphone

I have an iPhone master-detail storyboard app which uses two differ detail view Controllers (a create VC and an edit VC). From the master view, if I hit the "+" new button I segue programmatically to the create VC while if I choose a tableViewCell the program segues to the edit VC. All that is working just peachy. Now I want to be able to segue directly from the create VC to the edit VC. Problem is I end up with the exception 'Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
My storyboard looks like this.
I've also tried embedding my detail VCs in navigation VCs without success.
Also, keep in mind that I'm trying to go from a stack of
master->createDetail
directly to
master->editDetail
not
master->createDetail->editDetail.
I really just want to pop off the createDetail and replace it with an editDetail.

Suppose there are 2 parameters to send on next view as CustomerName and Email then code will be :
-(IBAction)btnNextViewClicked:(id)sender
{
UIStoryboard * myStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
NextViewController * nextView = [myStoryboard instantiateViewControllerWithIdentifier:#"nextViewCNTR"];
nextView.validEmail = #"abc#gmail.com";
nextView.customerName = #"ABC";
[self.navigationController nextView animated:YES];
}
If U dont have parameter then :
-(IBAction)btnNextViewClicked:(id)sender
{
UIStoryboard * myStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
NextViewController * nextView = [myStoryboard instantiateViewControllerWithIdentifier:#"nextViewCNTR"];
[self.navigationController nextView animated:YES];
}
nextViewCNTR is name of indentifier to put on flow line while desingning in XCode.
Use and let me know feedback.

use a UIContainerView in your detailview

Related

Trying to go from one view controller to another in a story board

I'm writting my first app using a storyboard. Before I had the following code to go from one view controller to another. But..this code needs a NibName. How would I do this going from screens created in a storyboard?
if (mDisplayCard==nil)
{
mDisplayCard = [[cDisplayCard alloc]
initWithNibName:#"cDisplayCard"
bundle:[NSBundle mainBundle]];
}
// [ mDisplay SetUp];
[self.navigationController pushViewController: mDisplayCard animated:YES];
A line like the following will instantiate a new view controller from a storyboard:
UIViewController *newViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"<identifier-from-storyboard>"];
It is assumed that your current view controller was instantiated from the same storyboard, so that self.storyboard is not nil. For the view controller that you want to instantiate, you'll have to make sure that you set a storyboard ID for it, which is what you'll put in for the identifier.

XCode5 self.navigationController pushViewController:animated: doesn't open the new viewcontroller

I'm not sure why but in Xcode 5 working on a project of IOS6.1 I have a button connected to a IBAction in which I'm trying to navigate to a new view controller.
I've tried two different codes to create the viewController and then push it to the navigation in both cases the view controller is not nil and both cases the viewController doesn't appear.
first try: with story Id - I've set the story id of the view controller to imageCapture and set the class to VSImageCaptureViewController
VSImageCaptureViewController* imageCaptureViewController = (VSImageCaptureViewController*)([self.storyboard instantiateViewControllerWithIdentifier:#"imageCapture"]);
[self presentViewController:imageCaptureViewController animated:NO completion:nil];
second try: with the name of the viewcontroller
VSImageCaptureViewController *imageCaptureViewController = [[VSImageCaptureViewController alloc] initWithNibName:#"VSImageCaptureViewController" bundle:nil];
[self.navigationController pushViewController:imageCaptureViewController animated:YES];
can you see something wrong or do you think I forgot to initialize something
Check to see if self.navigationController is nil.
If it is nil that means that you are not running within the context of a UINavigationController (the system sets this property for you when the UIViewController is added to a nav stack).
If this is the case then you have not properly set up a UINavigationController.
Note that you can not set the navigationController property yourself. The systems sets it for you when the UIViewController is added to a UINavigationController's stack (and sets it to nil when it is removed from the stack).
To set this up you will usually create a UINavigationController instance right after you create your main view controller.
UIViewController *mainViewController = ...;
UINavigationController *mainNavController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
// now present the mainNavController instead of the mainViewController
If you are using storyboards you would drag out a UINavigationController instance and replace the default root view controller with an instance of your mainViewController.

iOS Storyboard in xcode 4.5

I have started an iOS app with storyboard. In my app, mainStoryBoard starts with navigation controller. From navigation's view controller, I pass the controller to a second viewcontroller with a push segue by programatically ([self performSegueWithIdentifier:#"currencyClick" sender:self]). On the second view controller I have a button. On button click I want to go back to navigation's viewcontroller like [self.navigationController popViewControllerAnimated:YES] but here self.navigationController popViewControllerAnimated:YES is not working . In my project I unticked Shows navigation Bar in Navigationcontroller.
NavigationController-(root viewcontroller)-> viewController --(push segue with [self performSegueWithIdentifier:#"currencyClick" sender:self];)-->CurrencyViewcontroller
In currencyviewController I have a button. On button click I want to implement navigation back button click event. How do I implement a BACK Button programmatically, [self.navigationController popViewControllerAnimated:YES] is not working in this case.
Please help me to solve this problem..
Thanks in advance
to call secondcontroller in your first view controller use:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"mainStoryBoard" bundle: nil];
SecondViewController *rvc = (SecondViewController *)[storyboard instantiateViewControllerWithIdentifier:#"SecondViewControllerNameInYourStoryBoard"];
[self.navigationController pushViewController:rvc animated:YES ];
instead of self performSegue... Then in your second controller pop should work.

How i can navigate from View Controller to another View Controller once clicking on button?

I am getting this exception when I am trying to move to another view:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'NextViewController''
NextViewController *temp = [[NextViewController alloc]initWithNibName:#"NextViewController" bundle:nil];
[self presentViewController:temp animated:YES comletion:nil];
Firstly, check if you really have NextViewController.xib?
If No, then how can you load your nib file?
Also, check if you have NextViewController given as File's Owner class?
If yes,
Check, if you used have navigationcontroller?
If yes, then change your code to :
NextViewController *temp = [[NextViewController alloc]initWithNibName:#"NextViewController" bundle:nil];
[self.navigationcontroller presentViewController:temp animated:YES comletion:nil];
Exception says that you don't have the NextViewController.xib file in your project. Double check whether you have it or not.
Also make sure you have given the NextViewController as your File's Owner Class of NextViewController.xib
make sure you have the nib named NextViewController on your project. and also check if its added on your bundle resources. see screenshot
First you create uinavigationcontroller object first view set as a rootview controller after that set button on rootviewcontroller and push nextvie.
//for mainviewcontroller
UINavigationController *navigation =[[UINavigationController alloc]initWithRootViewController:viewcontroller];
[self.navigationController pushViewController:nextview animated:YES];
If you are using swift 3.0,try below code
//Here you can initiate your new ViewController
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "VadiveluPageViewController") as! VadiveluPageViewController
self.present(nextViewController, animated:true, completion:nil)
//if you need navigation controller use below
//self.navigationController?.pushViewController(nextViewController, animated: true)
Create 2 view controller in main story borad.
Go to main story board and select one view controller in main story board and drag and put into another view controller and select show method.
Make sure to create class and identifer name in second View Controller.
Go to Editor option and select navigation method. And put the below code in button action function.
self.performSegue(withIdentifer: "IdentiferName", sender: self)

iOS - performSegueWithIdentifier not working?

I have only two ViewControllers in my app
Storyboard setting: -
I have a push segue directly connected from my ViewController to MainTableViewController.I want to my app to redirect to Main View as soon as user enters the right passcode.
Here is my code: -
- (IBAction)checkInput
{
NSMutableString *aString = [NSMutableString stringWithFormat:firstDigit.text];
[aString appendFormat:secondDigit.text];
[aString appendFormat:thirdDigit.text];
[aString appendFormat:fourthDigit.text];
if([aString isEqualToString:#"1111"])
{
result.text = #"Right Password";
//UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MainStoryBoard" bundle:nil];
//UITableViewController *tvc = [self.storyboard instantiateViewControllerWithIdentifier:#"mainTableViewController"];
//[self.navigationController pushViewController:tvc animated:YES];
//[self removeFromParentViewController];
[self performSegueWithIdentifier:#"mainSegue" sender:self];
}
else {
result.text = #"Wrong Password";
}
NSLog(#"%#", aString);
}
checkInput is getting called as soon as user enters the last digit. I am calling it on Editing did End of my fourth TextField.
Any help would be really appreciated.
Thanks
The trick is that these segues only work when your view controllers are "embedded" in a UINavigation controller. Select your first VC, then choose (from the top menu) Editor > Embed In > Navigation Controller.
It should automatically set itself as the initial VC, but double check that.
Note that in this picture I am showing how, but it is already done, so you can see that it automatically connected my main VC to the Nav Controller.
Another idea is to embed your main view in a navigation view controller and use it as initial vc. Then present the passcode vc modaly when its needed on top of the main vc. Another advantage of this way is that you now can use popToViewController:animated: which you can not use this way at the moment.
initial vc ----> main vc
|
|
modaly
|
|
pass code vc