I have tried so many tutorials that I am wondering why I am not getting such a simple problem. I have a view controller called SetBudgetViewController. I have a text field in this view that I have connected as an outlet called *amountToSpend. I have another view used elsewhere in the app that has a label called *amountSet. How do I make the numbers entered into the first text field be displayed in the label in the other view? Thank you all so much (this is driving me mad)!
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
First, declare a property in the other view controller:
In SetBudgetViewController, in your -(void)prepareForSegue method:
In the other view controller, display the amount in viewDidLoad.
EDIT 2: Alternative for passing data between VCs not close to each other. You can repeat the action above or use NSUserDefaults.
In SetBudgetViewController after amount is entered:
In the other view controller, display the amount in viewDidLoad.
First of all you will need a way to know when the user has entered something in your first textview. One way of doing this is to implement a UITextField delegate and overwrite the textFieldDidBeginEditing method.
Next, you need to get the inputted data and send it to the second textView. A easy way of doing it would be to use NSNotificationCenter. Use it like this in your first view controller:
On your other view controller you need to add this on your init method:
And create the following method:
If you need to differentiate the sender of the notification, simply do
This way you have a reference to your initial textfield I hope this gives you a good ideea of how the NSNotificationCenter works. Good luck.
I hope this will work for you First View where to set User Default
.h File
in .m File
Now on click of button
the push your view or present modal as you want
then in the next view write as follow
Since you have lots tutorials, I guess you are enough in coding but not familiar with the concepts..
First of all, since these 2 controls are at different viewcontrollers, that means you have to build a connection between them to help the label find out what u entered in the text input. The connections could be delegate, notification or the plist value, so u will find lots solution here.
And for this scenario u mentioned, I would suggest delegate solution. Since you have tutorials, try to find the delegate section and realize what the delegate does and why.