0

戻るボタンの動作をカスタマイズしました。戻るが押された場合に BOOL を親ビューに送信したいのですが、bool 値は常に null です。

私の親.h


    [...skip...]

    BOOL myBool;

    [...skip....]

私の親.m


#import "theChild.h"

....


- (void)viewWillAppear:(BOOL)animated {
    NSLog(@"myBool is %d", (int)myBool);
}

-(IBAction)callTheChild:(id)sender {
    theChild *theChildVC = [[theChild alloc] initWithNibName:@"theChild" bundle:nil];
        // set something
    [self.navigationController pushViewController:theChildVC animated:YES];
    [theChildVC release];
}

私のtheChildで.m



#import "theParent.h"
....
....
-(void)backAction:(id)sender {

    theParent *theParentVC = [[addSite alloc] init];
    // set parent BOOL
    theParentVC.myBool = YES;
    [addVC release];
    // dismiss child view
    [self.navigationController popViewControllerAnimated:YES];
}

親が表示されると、myBool は null です。

私が変われば


    [self.navigationController popViewControllerAnimated:YES];


    [self.navigationController pushViewController:theParentVC animated:YES];

すべて正常に動作しますが、いくつかの理由で私が望むものではありません。

どんな助けでも大歓迎です。

ありがとう、マックス

4

2 に答える 2

2

ブール値を親に戻すのではなく、まったく新しいオブジェクトを作成し、代わりにブール値を与えています!

この行を見てください:

theParent *theParentVC = [[addSite alloc] init];

その行は新しい親オブジェクトを作成しました。おそらく元の親オブジェクトを使用したかったでしょう:)

theChild.hで

[snip]
theParentVC *parent;
[snip]

子を作成するとき

-(IBAction)callTheChild:(id)sender {
    theChild *theChildVC = [[theChild alloc] initWithNibName:@"theChild" bundle:nil];
    [theChild setParent:self];
    [self.navigationController pushViewController:theChildVC animated:YES];
    [theChildVC release];
}

親を更新したいとき

-(void)backAction:(id)sender {
    // Update the parent
    parent.myBool = YES;

    // dismiss child view
    [self.navigationController popViewControllerAnimated:YES];
}
于 2011-02-28T13:38:26.377 に答える
0

真の親にリンクバックするのではなく、新しいビューコントローラーを作成しています。

試す

self.parentViewController.myBool = YES;

それよりも

theParent *theParentVC = [[addSite alloc] init];
// set parent BOOL
theParentVC.myBool = YES;
于 2011-02-28T13:34:48.080 に答える