我有两个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 之前布尔值已经为真,这不应该发生。