Here how my storyboard looks like:
Initially when the users taps one of the squares, scene passes to the second one. At this point when the user closes the application and reopens it I want the second scene to come up.
I dont mind if first scene loads and then passes to the second one but I want second scene to show up.
Thanks in advance..
EDIT: I read that I can use generic segue but even if I create a generic segue with control drag from first view controller to the second one and using the code below nothing happens:
[self performSegueWithIdentifier: #"switch" sender: self];
SOLUTION:
You got to have a navigation control :)
In order to user the code below:
[self performSegueWithIdentifier: #"switch" sender: self];
You need to have a navigation control.
Related
enter image description here
This is my current swift code in Xcode. I have 2 problems, the first one being unable to control-drag the textfield to the code. The second one is how to transition from the first scene to the second scene.
first scene is the access_code one,
the second is the map view.
I want to be able to have the user enter an access code in the text field, and when they hit return. the program will change the view to the map view. (the user will get different maps based on the code they enter).
Thanks
For the first problem, I see that on the right side you have manual UIViewController set.
If the UIViewController on the right is not matching scene to the right it will not work. (You can't drag text field to the code.) It is very hard to say what is wrong but this could be a clue.
Second think is transition between two scenes.
You will need to create segue between those two screens. You dreg from first UIViewController to another in storyboard and give this seque the identifier.
Then in code, inside method where return key is pressed, call
performSegue(withIdentifier: "myIdentifireSetInStoryboard", sender: self)
To get method that is called when return key is pressed, look into UITextfieldDelegate method textFieldDidEndEditing...
I hope it help.
When I use CTRL+Click on next view it don't use the IBAction but goes straight to the next view.
How can I make the app use the IBAction first and then go to the next view.
The IBAction add data to the database, in the next screen I want to add some more data, I know how that works but can't go to the next screen and add the data...
Sorry for the messy description but hope you understand
If I understand your question correctly you want to do something on button-click, then perform a segue.
Make a general segue from your viewcontroller, not from the button.
Connect IBAction like normal.
In your IBAction method - use self.performSegueWithIdentifier("MyIdentifier")
As per my understanding if you can go to next view on button action using below code..
First go to Identity Inspector --> give Storyboard ID to Next View that you want to go..
-(IBAction)buttonAction:(id)sender{
[self.navigationController pushViewController:[self.storyboard instantiateViewControllerWithIdentifier:#"storyBoardIdentifier"] animated:YES];
}
Hope it helps you..
I've got a two View Controllers, when user press a button on the first one - app segue to the second one. But problem is that I need to use custom animation of segue. There is array of images, that must be animated before segue.
I guess that I need to create child-class myStoryboardSegue and override some method, but I don't even know which one.
Hope you can help me to understand.
After struggling for days on firing a segue conditionally, I managed to solve it thanks to Simon's answer here. Please take a moment to have a look or you might not understand what I'm talking about below. I didn't copy paste his answer because he's already explained it nicely over there.
Now I've faced a new question. What if I have multiple View Controllers that I want to segue to from one View Controller?
To explain it further : Say I have one MainViewController with 2 buttons. When clicked upon each button, it should segue to their respective View Controller. First button to FirstViewController and the second button to SecondViewController.
The method described in Simon's answer can be used when you segue from one View Controller to another View Controller. Since in that method, you tie the segue to the View Controller itsrlf and not to the button, you have only one segue with an identifier for that particular View Controller. Therefore I cannot distinguish between the button taps separately.
Is there a workaround to solve this problem?
Thank you.
It might be bit premature to say this but I guess you should look into Segue more deeply.
Yes you can perform segure from button. Just control click the button and drag the cursor to view controller you want it SEGUE'd. And from my understanding only condition there is each button tap results a segue to a fixed view. There is no condition there.
Also, you can push the navigation controller manually by
YourViewController *destViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"YourDestinationViewId"];
[self.navigationController pushViewController:destViewController animated:YES];
UPDATE:
prepareForSegue is too late to stop a segue from proceeding. Yes you can create multiple segues from your view to other view controllers. And in this case you have to do so. Don't reate a segue from button, just define a IBACtion on the button click you can do the validation from there,
if(validationSuccess) {
[self performSegueWithIdentifier:#"segue1" sender:self];
}
if you are using ios6
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
return YES on validation success and NO on failure to stop it from proceeding.
I suggest you look a bit at reworking your code logic.
If I understand correctly, you have a VC (embedded in a Nav. Controller) with 2 buttons and you have figured out how to segue each button to a different VC.
Your problem is you want to make sure that even if one of the buttons are pressed, a validation is done before an action takes place. I would advise this is bad User Interface design because the user has the illusion that this button might do something and then they click it and nothing happens.
UIButton can be connected to IBActions (to initiate actions) and IBOutlets (to set their properties). If this is a button created in IB directly, I would connect it to your class as an Outlet property:
#property (nonatomic,weak) IBOutlet UIButton* myButton;
And then set its enabled value:
self.myButton.enabled=NO;
This will keep the button and dim it. This is much better UI design and the user knows they should not press the button because some condition is not satisfied.
I would rework the code so that you set this value as disabled by default for example and enable it appropriately in your code whenever your "condition" is satisfied.
Obviously if this button is created programmatically (in your code without IB) then it is easy to just use the second command above.
Hope this helps.
I just wrote another way to call multiple detail views from a single table. Each cell could essentially make a different view be displayed. The code is similar to what you see in this post but you essentially use identifiers and attributes on the list item to determine which view to show.
https://codebylarry.com/2016/07/15/multiple-detail-views-in-swift/
override func tableView(tableView: UITableView,didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.row == 1 {
self.performSegueWithIdentifier("secondView", sender: self)
} else {
self.performSegueWithIdentifier(“others", sender: self)
}
}
I'm facing the following problem during the implementation of my app.
I've a tabbed application and clicking on each tab I can access to the corresponding view: for example, clicking on tab2 opens view2. But I can access to view2 also by clicking on a button on the view1 that is made as follows:
...
[buttonToView2 addTarget:self action:#selector(gotoView2) forControlEvents:UIControlEventTouchUpInside];
...
where:
- (void)gotoView2
{
//execute segue programmatically
[self performSegueWithIdentifier: #"View2Segue" sender: self];
}
View2 has a table that shows data of an array populated with data from the internet (in viewDidAppear method).
So, both selecting tab2 or clicking the button should bring the user to the destination view2.
This works but has a different behavior in the two cases:
If I click on the tab, the table is already populated with data while the application retrieves information from the internet
If I click the button and I perform the segue, the table is empty while the application retrieves information from the internet
Why? Maybe because of selector invoked by the button is executed on a different thread?
Any ideas please?
Regards,
yassa
Everytime a Segue is performed it creates a new instance of the destinationViewController (in this case view2). Meaning you have 2 separate instances of view2.