App crashes after embedding in navigation controller - ios

!(http://s10.postimg.org/8gy1q2rrt/question.png)
When i get to the last view controller on the right and press BACK button I Go back to the 1st controller not the second , i want to go back 1 step. (1>2>3). so i added navigation controller between them (don't know why ) , and app crashes when I want to go to the 3rd viewcontroller . all segues are PUSH.
This is BUTTON #1 CODE. #"tevzeulimenu" is the ID of the tabbarcontroller.
- (IBAction)goMenu1:(id)sender {
UITabBarController *firstView = [self.storyboard
instantiateViewControllerWithIdentifier:#"tevzeulimenu"];
[self.navigationController pushViewController:firstView animated:YES];
}
And this is code for segue:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"show1"])
{
DetailMenuViewController *detailViewController =
[segue destinationViewController];
NSIndexPath *myIndexPath = [self.tab1
indexPathForSelectedRow];
long row = [myIndexPath row];
detailViewController.detailMenu= #[_menu1Images[row],
_menu1Names[row],
_menu1Prices[row],
_menu1Text[row]];
}
}
Help to solve this problem. I want to go back from the 3rd view controller on the right(the last one) to 2nd when pressing back and not to the 1st.

You should use :
- (IBAction)goMenu1:(id)sender {
[self performSegueWithIdentifier:#"show1" sender:self];
}
Of course you have to add a Segue in your storyboard with the identifier : show1.
Hope that will help.
EDIT: In the context.

Related

Segue is executed twice

I am trying to transition between view controllers with a segue. It is navigating correctly but it is running twice.
Here is my code:
- (IBAction)onActionNext:(id)sender {
if ([[nameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]isEqualToString:#""]) {
}else if([[emailField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:#""]){
}else if([[mobileField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:#""]){
}else{
[self performSegueWithIdentifier:#"VerifyNext" sender:sender];
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:#"VerifyNext"]) {
// Get destination view
OTPSceneViewController *vc = [segue destinationViewController];
[vc setTitle:#"myapp"];
}
}
If even after commenting this line segue still run then as #mikealter said segue is connected your button. Check if when you check for when you click segue what it highlights.
A button like:
Or A View Controller like:
If you fall in first case that means your segue is connected to a button and, that is the reason why it opens next page even if you comment your code. And 2 times when you keep code(one from storyboard and another from code).
Edit:
If you want to call next page from code only. Remove Segue. Then reconnect it with view controller like:
First, whenever you create a segue (i.example) FROM a Button TO a View Controller, you are creating the link between VC1 and VC2.
If you run your project you will see that the segue works navigating from one VC to the other one.
This means that it already performs the segue, so if you declare an ACTION for your button and make a call to - perform segue... - it will run twice.
Note: if you call performSegueWithIdentifier is probably because you want to pass some data via SENDER. In that case you (obviously) need to call the segue ONCE, so instead of creating the segue from the button to the next VC, (first delete that segue), create a new one FROM the VCOrigin to VCDestination -> there are many ways to do it, but from the Interface Builder is as simple as right click on the top yellow rounded icon and drag&drop on the destinationVC. Don't forget to set the identifier on the Attributes Inspector.
Now, in your button~Action make the call to performSegueWithIdentifier and pass the data.
if you stop storyboard segue use following method:
override func shouldPerformSegueWithIdentifier(identifier: String,sender: AnyObject?) -> Bool {
return false
}
You don't even add
[self performSegueWithIdentifier:#"VerifyNext" sender:sender];
in onActionNext method if you add the segue in storyboard
If you want to navigate to next view controller use above line.
Preparing for the Segue
In order to pass information from one view controller to another using
the UIStoryboardSegue object we’ll need to take advantage of the
current view controller’s prepareForSegue:sender: method.
But If you call both,it calls two times.So make sure that whether you want to pass information or data to next view controller or just navigate the view.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSLog(#"prepareForSegue: %#", segue.identifier);
if([segue.identifier isEqualToString:#"VerifyNext"])
{
VerifyNextViewController *verifyNVC = segue.destinationViewController;
verifyNVC.name = #"Prashabt";
verifyNVC.id = #"1234";
}
else if([segue.identifier isEqualToString:#"VerSeg"])
{
AnotherViewController *anotherVC = segue.destinationViewController;
anotherVC.name = #"Sharma";
anotherVC.id = #"3245";
}
}
have a look of this question this may sure rectify
or there is another way to navigate to another view controller using below code.
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:#"viewControllerName"];
[self.navigationController pushViewController:vc animated:YES];
make sure you give identity to the view controller using identity inspector see image.

Tab bar with slide out menu

RearViewController.m
-(IBAction)unwindFromViewController:(UIStoryboardSegue *)segue
{
if ([segue.identifier isEqualToString:#"unwindToViewController"]) {
ViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewController"];
[self presentViewController:detail animated:YES completion:nil];
}
}
If I click back from my RearViewController the ViewController is not presented instead it just peeps and goes off(again shows RearViewcontroller).
Image2
I give you a solution for your question.
1.First remove triggered segue connection.
2.After that give push segue connection to Back to your required view controller.
3.Click Back Button Segue and give Identifier name as "goToMainViewController" or whatever you want just give there.Also segue should be "push".
Thank You

Passing data between controllers gives an error due to complicated segue

I have a modal segue which goes from a view controller to a tab bar controller which is embedded in a table view as you can see from this screenshot:
I want to pass data between the login screen and the table view. I use the following code:
-(IBAction)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"Enter App"]){
//Pass on username so that app can set everything up for that specific user
GamesListTableViewController *gamesList = (GamesListTableViewController *)segue.destinationViewController;
if ([segue.destinationViewController isKindOfClass:[GamesListTableViewController class]]) {
NSLog(#"ENTERING PROPER CLASS");
}
else{
NSLog(#"ENTERING WRONG CLASS");
}
gamesList.userID = self.userID;
}
}
My app crashes due to the last line of code. And i checked why (as you can see in the code above) and the reason is that the segue destination is not the GamesListTableViewController, but what i am assuming is the tab bar controller. How to i work around this problem?
UITabbarController *tabController = (UITabbarController*) segue.destinationViewController;
UINavigationController *nav = (UINavigationController*) tabController.viewControllers[0]; // or some other nr
GamesListTableViewController *tvc = nav.topViewController;

navigation bar back button repeated

I have a tableView with push segue to a detailView, and in this second view a button that perform a segue to a map location.
My problem is the back button of navigation bar appear twice (different icons also) in the map location view.
I guess is something of pushing twice the navigationbar, but I can't resolve it.
and this the method that I use to perform segues, to the detail view first
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"segue_ID"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
//here I pass info between views
DetailView *destViewController = segue.destinationViewController;
}
}
and to the map:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showMap"]) {
MapViewController *vc = [segue destinationViewController];
//here I pass info between views
vc.object = self.object;
}
}
Any help? please
Have you put in LeftBarButtonItem, and also BackButtonItem for your nav bar?
Try making one of them nil.

UITableView with toolbar and multiple segues

I have a simple storyboard file with a table view inside a navigation controller. If you cick one of the cells it goes to the details view. Great.
Then I tried adding a toolbar button and hooking it up to my table view controller. The button and the seque seems to work fine, except now, when i click on one of the table cells, the modal view is triggered.
So it seems I have done something wrong, but I don't understand what.
// called by pressing the add button in the toolbar
- (IBAction)showAddEventView:(id)sender {
[self performSegueWithIdentifier:#"showAddEvent" sender:sender];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showAddEvent"]) {
AddEventVC *addEventVC = [[AddEventVC alloc] init];
// set some property
} else {
EventIndexVC *eventIndexVC = [segue destinationViewController];
eventIndexVC.eventTitle = [self.events objectAtIndex: [[self.tableView indexPathForSelectedRow] row]];
}
}

Resources