How can I outsource the view change operations from my view controller on accelerations?
I have a view controller class. I want to do some things in my opinion when the accelerometer detects motion and calls the accelerometer: didAccelerate: method in the delegate object.
This delegate object is the problem here in my brain. Currently my brain is freezing and I don't know which would be better. Let me know what you think!
Solution 1) In my opinion, the controller class i conforms to the UIAccelerometerDelegate protocol and implements this accelerometer: didAccelerate: method. In the -applicationDidFinishLaunching: method of my AppDelegate class, I've set this view controller object as a delegate to receive method calls on accelerations. I think this is not very good.
Solution 2) I create an empty new object called AccelerationDelegate, conforming to this UIAccelerometerDelegate protocol, implementing this accelerometer: didAccelerate: method and in the -applicationDidFinishLaunching: method of my AppDelegate class. I have set this view controller object as a delegate to receive method calls on accelerations.
But for solution 2, my brain got stuck a bit! How do I access view objects from my view controller inside this object?
The problem is I have multiple view controllers. I am using a tab bar controller to switch between them.
Any suggestions how can I get this right?
a source to share
If your speedup is for a single view controller, then it makes sense to make the view controller get the information it needs to change its own subzones. However, it would be better to set up the view manager as a delegate when the view appears, and set the delegate to null when it disappears. (In particular, - (void) viewWillAppear:
and - (void) viewWillDisappear:
)
a source to share
I agree that the second method is better. You want to access only the currently selected tab stop, or just a specific view in your application.
Anyway, I would like to set up the properties for UITabViewController
in UIApplicationDelegate
so that you can access it from the delegate (you can get the application delegate by calling [[UIApplication sharedApplication] delegate]
). For instance:
YourApplicationDelegate *appDelegate = (YourApplicationDelegate *)[[UIApplication sharedApplication] delegate];
FirstUIViewController *firstViewController = appDelegate.firstViewController;
[firstViewController doStuff];
where firstViewController
is a property of your delegate.
a source to share