iOS 5でクラッシュするdismismodalviewcontrollerAnimated:(およびdismissViewControllerAnimated)
-
27-10-2019 - |
質問
論理的な説明は見つかりませんが、iOS 5(xcode 4.2)、shindmodalview:* animated:はい、dismissmodalviewAnimatedを呼び出すことができます:*順調ですが、最新のmodalview:*アニメーション:いいえ: 、その後、解雇方法を呼び出します。 (新しいPresentViewController:Animated:compley: + dismissViewControllerAnimated :)を使用すると、これは同じように機能します。私は今のところこれを回避しようとしています(プレゼンテーションをアニメーション化したくありません)。バグをAppleに報告しますが、しばらくの間これに頭を打ちました。すべての提案は大歓迎です。 iOS 5にはあまり存在しないので、できれば助けてください。 iOS 4またはiOS 5でクラッシュしないサンプルコード:
LoginController *loginController = [[LoginController alloc] initWithNibName:@"LoginControllerGG" bundle:nil];
[self presentModalViewController:loginController animated:YES];
[loginController release];
...
[self dismissModalViewControllerAnimated:YES];
これは、iOS 5でexc_bad_accessが解雇コールでクラッシュします。
LoginController *loginController = [[LoginController alloc] initWithNibName:@"LoginControllerGG" bundle:nil];
[self presentModalViewController:loginController animated:NO];
[loginController release];
...
[self dismissModalViewControllerAnimated:YES]; //crashes with EXC_BAD _ACCESS
1つの注:viegddolowで発生するログインコントローラー内にアニメーションがあります。それを取り出すかどうかを確認するつもりですが、できるだけ早く解決策が必要なので、これをそこに出したかったのです。
編集]完全なコードフロー... appdelegate、アプリケーション:didfinishlaunchingwithoptions:
if (!loggedIn) [myViewController showLoginPanel];
MyViewController:
- (void)showLoginPanel {
LoginController *loginController = [[LoginController alloc] initWithNibName:@"LoginControllerGG" bundle:nil];
if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]) {
[self presentViewController:loginController animated:NO completion:nil];
} else {
[self presentModalViewController:loginController animated:NO]; //iOS 4 works fine with or without animation
}
[loginController release];
}
LoginController:
- (IBAction)closeLoginWindow {
[[NSNotificationCenter defaultCenter] postNotificationName:@"CloseLoginWindow" object:nil];
} //doing it this way because calling on the self.parentViewController doesn't work
MyViewControllerに戻る:
- (void) viewDidLoad
...
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeLoginWindow) name:@"CloseLoginWindow" object:nil];
...
- (void)closeLoginWindow {
if ([self respondsToSelector:@selector(dismissViewControllerAnimated:completion:)]) {
[self dismissViewControllerAnimated:YES completion:nil]; //iOS 5 crashes only if presentation was not animated
} else [self dismissModalViewControllerAnimated:YES]; //deleting the previous condition, iOS 5 still crashes if presentation was not animated
}
解決
iOS5では、ライフキャイルの管理が何らかの形で変化し、その問題を詳細に説明することはできません。とにかく、修正は、ApplicationDidfinishlaunchingでそのワークフローをApplicationDidBeComeactiveに延期することです。 ApplicationDidfinishlaunchingのCall of ApplicationDidfinishlaunchingで正確に初期化されていないようです。
- (void)applicationDidFinishLaunchingWithOptions:... {
// in order to do this only at launching, but not on every activation
// Declaration as property for example
applicationDidLaunch = YES;
}
- (void) applicationDidBecomeActive:(UIApplication *)application {
if (applicationDidLaunch) {
applicationDidLaunch = NO;
[Start your login Workflow with modal view presenting here]
}
}
あなたのフィードバックに興味があります:) ....
他のヒント
2セントを追加します。ImagePickercontrollerを使用して、ピッカーを手動でリリースしなかった場合にのみ、その解雇を受けました(iOS 5 SDK)。
そう。あなたの場合、私はそのような回避策を提供することができます:1。行を削除 - [logincontrollerリリース]; 2.メモリリークを防ぐために、現在のコントローラーにログインコントローラーをプロパティとして追加し、現在のコントローラーのdealloc()でのみリリースします。
@interface myViewController : UIViewController
@property (nonatomic, retain) LoginController *loginController;
@end
...
@implementation myViewController
- (void)showLoginPanel {
self.loginController = [[LoginController alloc] initWithNibName:@"LoginControllerGG" bundle:nil];
// ... something goes here
}
-(IBAction)loginClose()
{
// this should close all windows as far as you call it from current (main) controller
[self dismissModalViewControllerAnimated:YES];
// ... then anything you want EXCEPT [loginController release];
}
-(void)dealloc()
{
[loginController release];
}
@end
幸運を :)
psこれを書いたばかりなので、それをだまする方法のアイデアです。何人かは私を訂正するかもしれません...とにかくそれは私のために働いていました。