0

次の問題があります。

UIViewController クラスを持つ 3 つのビューを含むストーリーボードがあります。私はシークを使用せず、初期ビュー (ビュー A と呼びます) を除いて、他のすべてのビューは presentViewController メソッドを使用してプログラムで作成されます。私が抱えている問題は、AがpresentViewControllerでBを開き、次にBがpresentViewControllerでCを開くとき、dismissViewControllerAnimatedでCを閉じると(Cには、C UIViewControllerへのアウトレットを備えたボタンがあり、自分でdismissViewControllerAnimatedを呼び出す)、Cビューが消え、B appers が 0.1 秒しか表示されず、C View が再び表示され、その後閉じるボタンが機能しなくなります。

理由は何でしょうか?

よろしくエディン


//delegate definition used between controller A/B and B/C
@protocol ParentControllerDelegate <NSObject>

//called as delegate method from B on A and from C on B to dismiss B from A and C from B
- (void)dismissView:(UIViewController*)controller;

@end


// MainMenuViewController.h which is controller A
@interface MainMenuViewController : UIViewController <ParentControllerDelegate>

//Controller B property
@property (strong, nonatomic) ChooseLevelViewController *chooseLevelViewController;
//button to open controller B
@property (weak, nonatomic) IBOutlet UIButton *chooseLevelBtn;

@end

//MainMenuViewController.m - Controller A
@implementation MainMenuViewController

//called to present chooseLevelViewController which is controller B
- (IBAction)chooseLevelPressed:(id)sender
{
    if(self.chooseLevelViewController == nil)
    {
        self.chooseLevelViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ChooseLevelView"];
        self.chooseLevelViewController.parentControllerDelegate = self;
    }
    [self presentViewController:self.chooseLevelViewController animated:YES completion:nil];
}

//called from controller B over delegate mechanism to dismiss B
- (void)dismissView
{
    [self.chooseLevelViewController dismissViewControllerAnimated:YES completion:nil];
}
@end

// ChooseLevelViewController.h which is controller B
@interface ChooseLevelViewController : UIViewController <ParentControllerDelegate>

//Controller A as delegate
@property (assign, nonatomic) id <ParentControllerDelegate> parentControllerDelegate;
//Controller C property
@property (strong, nonatomic) ChoosePlayerViewController *choosePlayerViewController;
//button to dismiss B over delegate A
@property (weak, nonatomic) IBOutlet UIButton *backMainBtn;
//button to open C
@property (weak, nonatomic) IBOutlet UIButton *choosePlayerBtn;

@end

//MainMenuViewController.m - controller B
@implementation ChooseLevelViewController

//calling controller A as delegate to dismiss B
- (IBAction)backMainBtnPressed:(id)sender
{
    [self.parentControllerDelegate dismissView];
}

//presenting choosePlayerViewController which is controller C
- (IBAction)choosePlayerBtnPressed:(id)sender
{
    if(self.choosePlayerViewController == nil)
    {
        self.choosePlayerViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ChoosePlayerView"];
        self.choosePlayerViewController.parentControllerDelegate = self;
    }
    [self presentViewController:self.choosePlayerViewController animated:YES completion:nil];
}


//called from controller C over delegate mechanism to dismiss C
- (void)dismissView:(UIViewController*)controller
{
    [self.choosePlayerViewController dismissViewControllerAnimated:YES completion:nil];
}
@end

//ChoosePlayerViewController.h which is controller C
@interface ChoosePlayerViewController : UIViewController

//Controller B as delegate
@property (assign, nonatomic) id <ParentControllerDelegate> parentControllerDelegate;
//button to dismiss C over delegate B
@property (weak, nonatomic) IBOutlet UIButton *closeBtn;

@end

@implementation ChoosePlayerViewController

//calling controller B as delegate to dismiss C
- (IBAction)closeBtnPressed:(id)sender
{
    [self.parentControllerDelegate dismissView];
}
@end
4

1 に答える 1

2

自分自身を却下するビューを持つべきではありません。常に親ビューで子を却下する必要があります。

  • BはCを却下すべき
  • A は B を却下すべきである

詳細については、 http://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html#//apple_ref/doc/uid/TP40007457-CH111-SW14を確認 してください。

ここに画像の説明を入力

于 2012-08-22T16:42:54.400 に答える