私はしばらくこの問題に苦しんでいますので、どんな助けでも大歓迎です。
状況は次のとおりです。私のアプリケーションには、というUIViewController
サブクラスがありInitialViewController
ます。このビューコントローラにはUIButtonがあり、そのボタンを押すと、というNSObject
サブクラスが作成されMyEngine
ます。このようなもの:
@interface InitialViewController : UIViewController <MyEngineDelegate>
...
@end
@implementation InitialViewController
...
-(IBAction)pressedButton:(id)sender {
MyEngine *engine = [[MyEngine alloc] init];
[engine start];
}
内部では、ユーザーが選択できるようにstart
ViewController( )をモーダルに表示します。ConflictViewController
@interface MyEngine : NSObject <ConflictViewControllerDelegate>
...
-(void) start;
@end
@implementation MyEngine
...
-(void) start {
ConflictViewcontroller *cvc = [[ConflictViewController alloc] initWithNibName:@"ConflictViewController" bundle:nil];
cvc.modalPresentationStyle = UIModalPresentationFormSheet;
cvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
cvc.delegate = self;
UIWindow *window = [(MyAppDelegate *) [[UIApplication sharedApplication] delegate] window];
[[window rootViewController] presentModalViewController:cvc animated:YES];
}
@end
ConflictViewController
本当に簡単です。ユーザーが決定するのを待つだけで、ユーザーがボタンを押すと、にメッセージを送信し、delegate
自分自身を閉じます。
-(IBAction)didSelectConflict:(id)sender {
UISegmentedControl *seg = (UISegmentedControl*) sender;
[self.delegate didResolveConflictChoice:seg.selectedSegmentIndex];
[self dismissModalViewControllerAnimated:YES];
}
すべての接続を確認しました。すべてのデリゲートが正常に機能しています。何が問題になっているのかというと、MyEngineがユーザーの選択を受け取った場合、その実装はdidSelectConflict:
すべてのプロパティが失われているため、適切に続行できませんnull
。
MyEngine
presentsの場合ConflictViewController
、プログラムは実行を継続し、start
終了すると、プログラムに戻りpressedButton:
、このメソッドが閉じられると、MyEngine
オブジェクトが解放されます。
私が知りたいのは、これを回避する方法があるかどうかです。誰かがこのようなことを別の方法で行ったことがありますか?ここでの質問は、選択が複雑すぎて使用できない場合に、ユーザーの選択を適切に取得する方法UIAlertView
です。
長い質問で申し訳ありませんが、私はそれを可能な限り単純化しました。お時間をいただきありがとうございます。リンク、コメント、またはあらゆる種類のヘルプをいただければ幸いです。