iOS - performSegueWithIdentifier not working? - iphone

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

Related

directly segueing between different detail view controllers

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

Navigate from a ViewController to another

I have this design in my storyboard:
As you see the middle ViewController is connected to a Navigation Controller ( I just made the navigation bar invisible). In this middle page I add all the controls programmatically ( using Parse mobile platform login wizard ).
The thing is I want to navigate to the third page, when Login is done successfully.
- (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user {
[self dismissModalViewControllerAnimated:YES];
ViewController2 *viewController = [[[ViewController2 alloc] init] autorelease];
[self.navigationController pushViewController:viewController animated:YES];
printf("%s", [#"Ali" UTF8String]);
}
the message will be printed, but the navigation is failed. Can you help? Perhaps I need to fix something in storyboard.
I'm not sure you should be sending the dismissModalViewControllerAnimated: message. Are you presenting another view controller modally on top of your login view controller?
Anyway, when you have configured a view controller in a storyboard, you can't create the view controller using alloc and init. You need to ask the storyboard to create it. There are a couple of ways to do this.
One way
One way to get the storyboard to create your ViewController2 is to make a push segue in your storyboard.
Open your storyboard.
Control-drag from the login view controller to the ViewController2.
Choose the “push” segue type.
Click on the segue.
Choose View > Utilities > Show Attributes Inspector.
In the Attributes Inspector (right-hand side of the window), set the segue identifier to “didLogIn”.
To execute the segue, do this:
- (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user {
[self dismissModalViewControllerAnimated:YES];
[self performSegueWithIdentifier:#"didLogIn" sender:self];
}
Another way
Another way to get the storyboard to create your ViewController2 is to give it a storyboard ID and ask the storyboard to instantiate the view controller by ID. Then you can push the view controller.
Before you can ask the storyboard to create it, you must give a “storyboard ID” to the ViewController2 instance in your storyboard.
Open your storyboard.
Select the ViewController2 instance.
Choose View > Utilities > Show Identity Inspector.
In the Identity Inspector (right-hand side of the window), enter “viewController2”. Case is important!
Then, in your code, ask the storyboard to instantiate viewController2:
- (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user {
[self dismissModalViewControllerAnimated:YES]; // Should this be here?
ViewController2 *viewController = [[[ViewController2 alloc] init] autorelease];
[self.navigationController pushViewController:viewController animated:YES];
}
Try this way,
ViewController2 *myViewController=[storyboard instantiateViewControllerWithIdentifier:#"TheNameOfYourController"]
[self.navigationController pushViewController:myViewController animated:YES];
Because a lot of relevant code/settings is missing I would suggest the following:
Use this code:
-(void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user {
[self dismissViewControllerAnimated:YES completion:NULL];
Class klass = [[NSBundle mainBundle] classNamed:#"ViewController2"];
ViewController2 *viewController = [[klass alloc] init];
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];
NSLog("%#", #"Ali");
}
If that doesn't work check how you suppose to initialize ViewController2.
If all this doesn't help please try to post more relevant code.
To move next viewController using Storyboard Identifier
nextViewController *objnextViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"nextViewControllerIdentifier"];
[self.navigationController pushViewController: objnextViewController animated:YES];

PresentModalViewController in Storyboard programmatically iOS 5

I am using storyboards for FIRST time in my iOS app. I have 2 views in my Storyboard (A & B). Lets say A is my initial view controller in my storyboard. When my app launched, I can see view controller A. So far everything is working as per expectation. Now in my view controller A, I am checking whether user is logged in or not. If user is not logged in then I want to present view controller B. How can I show B modally using PresentModalViewController programmatically?
Here is my set up
Here is my code
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
if (!isUserLoggedIn) {
NSLog(#"USER NOT LOGGED IN....");
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
LoginViewController *vc = (LoginViewController*)[mainStoryboard instantiateViewControllerWithIdentifier:#"B"];
[self presentModalViewController:vc animated:YES];
}
}
What you have done so far seems correct.. Did you remember to actually set the identifier of B in the storyboard?
Also, you might want to try
[self.storyboard instantiateViewControllerWithIdentifier:#"B"];
instead of what you're doing.
Update:
Here's what the viewDidLoad method might look like:
- (void)viewDidLoad {
[super viewDidLoad];
if (!isUserLoggedIn) {
NSLog(#"User is not logged in.");
LoginViewController *vc = (LoginViewController *)[self.storyboard instantiateViewControllerWithIdentifier:#"B"];
[self presentModalViewController:vc animated:YES];
}
}
Also, I see from the image that your first view controller isn't set to any particular class. It just says "View Controller", while the second one shows "Login View Controller" correctly.
Note: I don't have access to Xcode right now, so I haven't tested it yet.

iOS 5 - navigation and tab bar not appear after presentModalViewController

i am developing an ios app and using storyboards generally. in my view controller named blackView (it has no xib file) there is a button to play video. that button goes to another view controller named videoViewController (videoViewController is not in storyboard it has xib file). after user clicks to done on the videoViewController user should return to the blackView and now all is work but after return to the blackView from videViewController the navigation bar and tab bar controllers of blackView not appear
how can i handle this? how can i get appear those navigation and tab bars on the blackView?
this is my code in my videoViewController.m file
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController * myview=[storyboard instantiateViewControllerWithIdentifier:#"blackView"];
[self presentModalViewController:myview animated:YES];
}
From your code i thing you are doing something wrong.
i need to ask one question to you that movieplayer in is presented od added as subview.
if you are presenting it then you need to do something like this in youe app.
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
[self dismissModalViewControllerAnimated:YES];
}

Pushing a new view on a navigation controller from a cell's view controller

I have a navigation view controller which navigates between some tableviews and I've just added an "edit" button inside the cells of one of the tables. What I'd like to happen is for the user to tap the edit button inside the cell and for the navigation controller to shunt across a new view where all of that cell's content is laid out for easy editing.
The cell, however, has no access to the navigation controller and cannot push a new view controller on to its stack. How can I do what I want?
Note that I am not using segues and storyboards as it's an old app and I want to continue supporting devices running iOS 4.
You should set the target of the button to the UIViewController that is already on the stack?
If you don't want to add this new view to the Navigation (Stack), Simply use the PresentModalViewController
// In action method for edit button
- (void)editButtonClicked {
EditViewController *editViewController = [[EditViewController alloc] initWithNibName:#"EditViewController" bundle:nil];
[self.navigationController presentModalViewController:editViewController animated:YES];
[editViewController release];
}
I'm not sure if you want this, but you can try:
// In action method for edit button
- (void)editButtonClicked {
EditViewController *editViewController = [[EditViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:editViewController animated:YES];
[editViewController release];
}