Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
felix flores
850 PointsSwitching Views and Passing data
I am trying to pass data from the Main View to a Second View. My first step was to flip horizontal the main view once a Button is pressed and visceversa for the Second view. But I set the button in the main view.m abd works perfectly but when I do the same for the second view it has a "Parse" error: Unknown type name referring to the Second View. ( the second view was properly imported to the main view. The funny thing is that if i test the first button from the main view to switch the second before coding the second button to switch it runs well and the supposed unknown name is not in that moment
4 Answers
Ben Jakuben
Treehouse TeacherCan you post the relevant code in here for us to take a look at?
felix flores
850 PointsBen, Thanks for your reply... I have sorted that problem out... I just started new projects several times until it ran. I didnt see you reply on time.... Ben by the way. I am intending to do something in my application that I dont know how to do... I am trying to click on a button to change the value in a input data given by the user contained in a text box. ( I am trying to change the units on that input data ..i.e multiply value by the conversion factor to go from imperial to metric or visceversa).. So once you convert the value the new value is in the same input text box. I also was thinking when I press the button for this action I would liketo switch the label on the button to "english" or "imperial" .. . Could you possible help me on this?
Ben Jakuben
Treehouse TeacherSounds like it should be pretty straightforward! The first thing you need to do is create IBOutlets for everything that you want to access from code when the button is pressed. This means one for the UITextView and one for the UILabel. You'll also need an IBAction for the button press itself
Then you should be able to use those to update the fields as you wish. Here's some pseudo-code that might help:
- (IBAction)convert:(id)sender {
// Get the input value from the UITextView
int inputValue = self.textView.text;
// Convert it to whatever you need...
// Store it back in the text view
self.textView.text = convertedValue;
// (This might vary depending on which data type you use for convertedValue)
// And update the label
if ([self.label.text isEqualToString:@"English"]) {
self.label.text = @"Imperial";
}
else {
self.label.text = @"English";
}
}
felix flores
850 PointsBen, Thanks for your prompt reply, I ll try that and see how it works ...I let you know
felix flores
850 Pointsfelix flores
850 PointsBen, Thanks for your reply... I have sorted that problem out... I just started new projects several times until it ran. I didnt see you reply on time.... Ben by the way. I am intending to do something in my application that I dont know how to do... I am trying to click on a button to change the value in a input data given by the user contained in a text box. ( I am trying to change the units on that input data ..i.e multiply value by the conversion factor to go from imperial to metric or visceversa).. So once you convert the value the new value is in the same input text box. I also was thinking when I press the button for this action I would liketo switch the label on the button to "english" or "imperial" .. . Could you possible help me on this?