我有2 viewcontroller
s,第一个VC包含backButton。
firstVC.h
@protocol DVDelegate <NSObject>
-(void)DVViewControllerDismissed:(NSString *)stringForFirst;
@end
并且还包含委托属性
@property (nonatomic, assign) id<DVDelegate> myDelegat;
firstVC.m
firstVC的backButton代码
- (IBAction)backButton_Click:(id)sender {
NSLog(@"EEEEEE:%@",_DFCJ);
if([_DFCJ isEqual:@"DL"]){
NSLog(@"159");
if([self.myDelegat respondsToSelector:@selector(DVViewControllerDismissed:)])
{
[self.myDelegat DVViewControllerDismissed:_DFCJ];//this method not call
NSLog(@"aPP");
}
[self dismissViewControllerAnimated:YES completion:nil];
NSLog(@"5555");
}
}
的 SecondVC.m
@interface DiamondListVC ()<DVDelegate>
收到以下方法
-(void)DVViewControllerDismissed:(NSString *)stringForFirst;{
NSLog(@"AASASS");
[self performSelector:@selector(callService) withObject:self afterDelay:0.1];
}
结果日志
2018-04-21 09:33:39.382 search[907:16573] EEEEEE:DL
2018-04-21 09:33:39.382 search[907:16573] 159
2018-04-21 09:33:39.383 search[907:16573] 5555
但是firstVC不会解散,请查看我的代码并给我一个建议。
提前致谢。
答案 0 :(得分:1)
由于firstVC
被firstVC
推送而未被提及,secondVC
无法被解雇的原因。
要将数据从firstVc
传递到secondVc
,您无需使用委托。您可以使用secondVC
从firstVC
获取self.navigationController.viewControllers
。
<强> FirstVC.m 强>
- (IBAction)backButton_Click:(id)sender {
NSLog(@"EEEEEE:%@",_DFCJ);
if([_DFCJ isEqual:@"DL"]){
NSLog(@"159");
// Get |SecondVC| by using |self.navigationController.viewControllers|
NSArray* viewControllers = [[self navigationController] viewControllers];
SecondVC *previousViewController = viewControllers[viewControllers.count - 2];
[previousViewController DVViewControllerDismissed:_DFCJ];
[self.navigationController popViewControllerAnimated:YES];
NSLog(@"5555");
}
}
<强> SecondVC.h 强>
@interface DiamondListVC : YourClass
-(void)DVViewControllerDismissed:(NSString *)stringForFirst;
@end