簡體   English   中英

通過NavigationBar的布爾槽后退按鈕

[英]Pass boolean trough back button of navigationBar

我有兩個viewController,即viewControllerB,當通過navigationBar的后退按鈕返回到viewControllerA時,我希望您傳遞一個布爾值。 我使用了一種協議,但不起作用。

在ViewControllerB.h中

 @protocol detailProgrammFiereDelegate <NSObject>
 @required
 -(void) addItemViewController: (ViewControllerB *)programmFiere withBool:(BOOL)booleanFiere;
 @end

 .....
 @property (nonatomic, weak)id <detailProgrammFiereDelegate>delegate;
 .......

在ViewControllerB.m中

- (void)viewDidLoad
{
     ......

     BOOL booleanFiere =YES;
    [self.delegate addItemViewController:self withBool:booleanFiere];
 }

在ViewControllerA.h中

@interface ViewControllerA: UIViewController <detailProgrammFiereDelegate>

在ViewControllerA.m中

-(void)addItemViewController:(DetailProgrammFiere *)programmFiere withBool:(BOOL)booleanFiere{

     //after pressing back button of viewControllerB not enter into this method. Why?

    if (booleanFiere){ //is already true before opening the ViewControllerB. Why?
        [self viewDidLoad];
    }
}
........

 -(void)getInformationsFiere:(id)sender{ //method that open ViewControllerB

     ViewControllerB * detailFiere =[[ViewControllerB alloc]initWithNibName:@"ViewControllerB~iPhone" bundle:nil];


    detailFiere.delegate =self;


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

   }

在打開ViewControllerB之前,布爾值已經為true,這應該不會發生。

如果要在從B返回A時傳遞參數,則不應將調用的委托方法放在viewDidLoad中。 當B是alloc和init時,將調用B的viewDidLoad,但在彈出B返回到A時將不調用B。這也是在B出現之前,A的booleanFiere已經為YES的原因。

你可以放

    [self.delegate addItemViewController:self withBool:booleanFiere];

就在您B的[self.navigationController popViewControllerAnimated:YES]之前,而不是在B的viewDidLoad中。 所以A的-addItemViewController:將在返回時被調用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM