I am making an app where the user inputs some numbers into a text field and it shoots out an answer on a label. I have the answer being displayed on another view controller. Using the same prepare for segue methods on all of the screens that I have only some of them work. The others will pass whatever text I have in the first view controller label (I have checked this by inputting all sorts of stuff and it shows up on the other side)... I have also deleted the segue and made sure that the calculation works and the label in the first view controller is getting the information.
This leads me to believe that the way it is set up is fine, but the segue happens so fast that the label on the first view controller will still have the original text when the segue is performed, sending that information over as a string instead of the answer...
Is it possible to change this? It would be the only logical thing that makes sense to me write at the moment. If it is possible how could this be fixed?
Any help would be appreciated. Thanks
EDIT:
This is the whole code I was Asked To post to help figure this out
So if in the first view controller I put a '?' for the text in the label just to hold the label, and in the second view controller I put a '!' in the answer label to hold the label.. The second view controller after I run the simulator the second view controller will show a ? the text from the 1st label... so it does show that it is pushing the data over, it is just not pushing the information in the label.
I think you have a made a segue to another view controller from the same button , with which you are performing the #IBAction func usednroicalc(sender: AnyObject), what you have to do is make a segue from view controller to another view controller in storyboard , give your segue an identifier and inside the #IBAction write at the place where you want to perform the segue , that is after your calculations write , self.performseguewithIdentifier("your identifier") . you can give identifier to segue by clicking on it and than find the identifier label in the inspector.
EDIT:
Here I have dragged from ViewController the one Highlighted as yellow in ViewController Scene to TableViewController the one above first responder in TableView Controller Scene.
Just wanted to answer my own question as I have found a way to push the info over finally...
You have to set up the calculations of the code in the prepare for segue and not in the button action. The button action is now only setup for the segue to the new view controller. not the way I wanted everything thing to go but it works.
Thanks everyone for the feedback... hope this helps someone else in the future.
Related
I have an initial ViewController that is a TableView with lots of data. I have a title bar button item that links to another TableView with a summary of the data in the first ViewController. I currently have it so that when you click on a cell, it redirects the user back to the first ViewController and scrolls them to the proper cells. However, it adds the view to the stack and doesn't actually move them back properly. I think I would be able to do this through Unwind segues, but I can't seem to get them to work through cell clicks. Is there a better way that I can achieve this?
When I switch to the other view, I also need to set two variables in the initial controller to tell it what index to scroll to.
1.UNWind Segue :
suppose that we need to programmatically trigger the backward navigation, based on an interaction with something other than the default “back” button on the navigation bar. How would you do it? Yep – you’ve got it: by using an unwind segue.
2.Other way is usual : PopViewController Method
As per your question , you can go with option 2 which is more easy .
As far as Sending data from SecondViewController to FirstViewController you can use delegate pattern to send data back.
Here is few useful post : https://stackoverflow.com/a/25523091/3400991
Feel free to comment. Thanks
I'm a beginner to iOS development, so forgive me if this is really basic. It's probably answered somewhere, but I've looked for a long time, and I'm struggling.
I have a second View on my story board that I've successfully linked to the first view using a Navigation controller and stuff, and I'm able to navigate to it. I can also add actions/outlets from elements on my first view by Control-dragging to the .h file.
I have a label on my second view, and I want to be able to do the same: add actions and outlets from elements. But when I try Control-dragging, nothing happens. What am I doing wrong, and how do I fix it?
Hmm, well first of all welcome to Stack Overflow! And thanks for asking the question.
Let me know if I have this right - you have two view controllers to the right (linked with segues) of a navigation controller and currently you can navigate to the second from the first using a button at the top right? Then when on the second view controller there's a nav button at the top left with a little arrow by it? And this should take you back to the first. Is that right?
Now on the second view controller you want to create a button that performs an action, but when you right-click-drag (ctrl-drag) onto a .h or .m file nothing happens?
If that's the case I've seen a few reasons for that. You might try:
You need to make a button, a label can only recieve actions, not create them. Read this article on IBOutlet vs IBAction
Restart Xcode (I know, it's lame, but humor me)
Make sure you're dragging (if on the .h file) between "#interface" and "#end"
Make sure you're dragging (if on the .m file) between "#implementation" and "#end"
Do you have a custom view controller class for your second view? If so, select the second view controller in your storyboard and go to the identity inspector. Set the custom class to your custom view controller's class name. Now you will be able to control-drag IBOutlets and IBActions.
I'm trying to execute code when a button is pressed for an application but I can't find how to change the views after the code is executed. Is there a way to switch views how I want to or is there another way? Thank you in advanced, I'm very new to xcode.
edit: I'm trying to go from one view to another, not the view controller and yes I have one storyboard that I planned on using for the whole project if possible.
To execute code when a button is pressed, you have to set up a method that the button is hooked into. Because you said you're using storyboards, I'll assume your button is on the storyboard. Go to the assistant editor, hold ctrl, and click-and-drag from the button to the view controller's .m file (#implementation section). This will create an IBAction method, and any code in this method will execute whenever you press the button.
The method will look like this:
- (IBAction)aButtonPress:(id)sender {
}
According to your comments, you say you only want to change the on-screen view, and not transition from one view to the next.
Views are added and removed with the following methods:
[aSuperview addSubview:aSubview];
[aSubview removeFromSuperview];
I can't really tell you much else with a lot more detail from you... and even though I asked twice in the comments and you said you only want to change the view, not the view controller... I think you probably need to transition to a new view controller. Impossible to know for sure as you've given almost no detail...
But if you want to transition between view controllers (which also transitions views), then ...
Create two view controllers on the storyboard. Hook them together with a segue, and give that segue a name. Now, to perform that segue in code:
[self performSegueWithIdentifier:#"YOUR_SEGUE_NAME" sender:self];
In the view controller that has a UITabBarItem, i realized that viewDidLoad() method only gets called the first time when the tab bar item is clicked. So I dont know how to bring up the dynamic graphics when it's clicked the 2nd time. Can some guru help me on this? thanks in advance.
Should I conform to some kind of delegates or should i do it within didSelectViewController method on the root controller of all the tab bars? If i do the later one, it just seems to be weird since i think the controller that has the corresponding tab bar item should render itself instead of doing the rendering on root controller..
You want to put any code that should run every time the view controller appears in viewWillAppear: instead of viewDidLoad. viewDidLoad is designed for code that should run when the view backed by your UIViewController is created (and then possibly re-created after being thrown away during low-memory situations).
Actually i resolved this by using the parameter passed into the callback didSelectViewController(param).
Using Storyboard I want to transition from UITableViewController to another ViewController on the click of Detail Disclosure button. I created a proper segue, but the transition does not happen when I run the application. Creating a segue from UIButton to a ViewController works properly. I tried embedding Navigation Controller in UITableViewController, it did not help.
Look forward to somebody helping me with this, as I have already spent four days on it.
Thanks!
Here's the most complete example I have found. Most have fallen short by not providing an example of how to go from the list of records to the detail of the selected records.
http://developer.apple.com/library/ios/#samplecode/SimpleDrillDown/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007416-Intro-DontLinkElementID_2
and here's the link to part 2 of the above tutorial:
http://www.raywenderlich.com/5191/beginning-storyboards-in-ios-5-part-2
It should work without any code on your side
Ctrl click the prototype cell (table cell) and drag it to connect with the detail view. This will pop up a segue window. I chose Push since I have a navigation controller - but you can use Modal as well.
Note the segue name should show "Segue from UITableViewCell to ).
I've put in the disclosure icon on the Table cell as well.