I have an app that switches around 10 different view controllers with such methods: / P>
- (IBAction) pg2button {pg2 * pg2view = [[pg2 alloc] initWithNibName: zero bundle: zero]; Pg2view.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; [Self current model view controller: animated pg2view: yes]; [Pg2view release]; } Before presenting the next scene, where is the best place to release the current view? Thanks! Format your question: Add at least 4 spaces to each code line.
(1) Format your question.
(2) Why do you use initWithNibName: bundle: initializer if you pass zero as NIB name?
Use only regular init .
(3) I see that you already release the View Controller.
Once you dismiss it in the background (in the background) it will be released.
(4) If you ask, "Where is a good place for to dismiss the present view before presenting it next?" So it depends on your structure.
Generally, the best way to add a representative method to the original view controller is to, the Model View Controller will call that delegate call and the original view controller will reject the model like this: [Self-Removed Geomodal viewer controller: * Yes]; .
Edit :
Code sample for the delegate:
// Protocol that is assigned to your original view controller by @protocol ModalViewControllerDelegate & Lt; NSObject & gt; @required - (zero) modalViewControllerDidCancel: (UIViewController *) modalViewController; - (zero) modalViewController: (UIViewController *) modalViewController didReturnWithResult: (NSObject) results; @end How to implement it:
@interface MainViewController: UIViewController & LT; ModalViewControllerDelegate & gt; {...} ... @end @implementation MainViewController ... #pragma Mark - #pragma Mark ModalViewControllerDelegate Methods - (Zero) modalViewControllerDidCancel: (UIViewController *) modalViewController {[self-dismissModalViewControllerAnimated: Yes]; } - (zero) modalViewController: (UIViewController *) modalViewController didReturnWithResult: (NSObject) result {// TODO: Do something with the result [self-dismissModalViewControllerAnimated: Yes]; } ... @end You should add the next code to your Model View Controller:
@interface ModalViewController1: UIViewController {... ID & LT ; ModalViewControllerDelegate & gt; Representative; ...} @ Property (assign) ID & lt; Modal Wii Controller Delegate & gt; Representative; ... @end @implementation ModalViewController1 @ synthesis representative; ... - Cancel (zero) Use user {... [self.delegate modalViewControllerDidCancel: self]; } @end
Do not forget to set yourself a representative property (with the main view controller) when you create a modal view controller ... < / P>
Comments
Post a Comment