dismisscontroller 委托方法不起作用
dismisscontroller delegate method not working
我有 2 个 viewcontroller
,第一个 VC 包含后退按钮。
firstVC.h
@protocol DVDelegate <NSObject>
-(void)DVViewControllerDismissed:(NSString *)stringForFirst;
@end
并且还包含委托 属性
@property (nonatomic, assign) id<DVDelegate> myDelegat;
firstVC.m
第一个的后退按钮代码VC
- (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不会dismiss,请看我的代码给我建议。
提前致谢。
之所以firstVC
不能解散,是因为firstVC
是从secondVC
推过来的,没有呈现。
要将数据从 firstVc
传递到 secondVc
,您不需要使用委托。您可以使用 self.navigationController.viewControllers
.
从 firstVC
获取 secondVC
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
我有 2 个 viewcontroller
,第一个 VC 包含后退按钮。
firstVC.h
@protocol DVDelegate <NSObject>
-(void)DVViewControllerDismissed:(NSString *)stringForFirst;
@end
并且还包含委托 属性
@property (nonatomic, assign) id<DVDelegate> myDelegat;
firstVC.m
第一个的后退按钮代码VC
- (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不会dismiss,请看我的代码给我建议。
提前致谢。
之所以firstVC
不能解散,是因为firstVC
是从secondVC
推过来的,没有呈现。
要将数据从 firstVc
传递到 secondVc
,您不需要使用委托。您可以使用 self.navigationController.viewControllers
.
firstVC
获取 secondVC
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