What are the possible ways to send data to previous view in iphone. Without using Appdelegate. Because there are chances for my view class to be instantiated again.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- how do you prevent page scroll in textarea on mobi
- Custom UITableview cell accessibility not working
相关文章
- Could I create “Call” button in HTML 5 IPhone appl
- Unable to process app at this time due to a genera
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Open iOS 11 Files app via URL Scheme or some other
- Can keyboard of type UIKeyboardTypeNamePhonePad be
- Can not export audiofiles via “open in:” from Voic
- XCode 4.5 giving me “SenTestingKit/SenTestKit.h” f
There are several ways to achieve data sharing, with Singleton Objetcs being one of the most popular:
Objective C Singleton
I believe the best approach is using the
NSNotificationCenter
class. Basically what you do is register an object (as an observer) with a notification center.So for example if you have objects
A
andB
.A
registers as an observer. Now lets sayA
is the "previous" object you are talking about, you can haveB
send a notification (data or message) to the notification center which then notifies objectA
(and any other registered observers).Example:
In file
ClassA.m
register as shown below:didSomething
is the method which receives the notification sent by objectB
. This will look something likeFinally you send the message below from whatever method in
ClassB.m
to notify/send data to objectA
Seems convoluted but it's the best approach in my opinion (and quite simple once you understand it :)).
If the view you want to communicate with is a parent view (e.g. the previous view's view controller is where you created this view) then you probably want to handle dismissing the view in the previous view controller. When you do that, you can read the data that has changed and update the previous view controller with the new data.
Then in the viewWillAppear: method of the previous view controller, update the actual views to reflect the current state of the view controller.
Edit: I've just noticed that your newView is transparent. If this is the case, then you certainly want to route all logic through your view controller. You should only have one view controller with visible views at a time.