页面传值

页面传值:从A到B,然后从B回传到A。只需要实现IUINavigationControler协议

#import <UIKit/UIKit.h>



#pragma mark - 
#pragma mark - IUINavigationContoller
/**
 *@protocol
 *IUINavigationController
 *@discussion
 */
@protocol IUINavigationController <NSObject>

@required
///导航到页面并携带参数
- (void)NavigateTo:(NSDictionary *)param withFromClassName:(Class)c;

///返回到页面并携带参数
- (void)NavigateBack:(NSDictionary *)param withFromClassName:(Class)c;
@end



#pragma mark -
#pragma mark - UINavigationControllerExtends
/**
 *@class
 *UINavigationController 类
 *@discussion
 */
@interface UINavigationController (UINavigationControllerExtends)

///跳转到页面,并携带参数
- (void)naviagteToWithPageName:(NSString *)name withParam:(NSDictionary *)params;

///跳转到页面
- (void)naviagteToWithPageName:(NSString *)name;

///返回页面,并携带参数
- (void)goBackWithParam:(NSDictionary *)params;

///返回页面
- (void)goBack;

@end




#import "UINavigationController+UINavigationControllerExtends.h"
#import "Utils.h"


@implementation UINavigationController (UINavigationControllerExtends)


- (void)naviagteToWithPageName:(NSString *)name withParam:(NSDictionary *)params{
    UIViewController *vc = [self CreateVCWithXIB:name];
    if ([vc conformsToProtocol:@protocol(IUINavigationController)]) {
        id<IUINavigationController> navigate = (id<IUINavigationController>)vc;
        [navigate NavigateTo:params withFromClassName:[self.visibleViewController class]];
        NSLog(@"跳转到%@页面,携带参数%@",name,params);
    }
    [self myAnimationPush];
    [self pushViewController:vc animated:NO];
}

- (void)naviagteToWithPageName:(NSString *)name{
    UIViewController *vc = [self CreateVCWithXIB:name];
    NSLog(@"%@",vc);
    [self myAnimationPush];
    [self pushViewController:vc animated:NO];
}

- (void)goBackWithParam:(NSDictionary *)params{
    Class c = [self.visibleViewController class];
    [self myAnimationPop];
    [self popViewControllerAnimated:NO];
    UIViewController *vc = self.visibleViewController;
    if ([vc conformsToProtocol:@protocol(IUINavigationController)]) {
        id<IUINavigationController> navigate = (id<IUINavigationController>)vc;
        [navigate NavigateBack:params withFromClassName:c];
        NSLog(@"返回页面%@传递参数%@",c,params);
    }
    
}

- (void)goBack{
//    [self myAnimationPop];
//    [self popViewControllerAnimated:NO];
    [self goBackWithParam:nil];
}

- (UIViewController *)CreateVCWithXIB:(NSString *)xibName{
    UIViewController *control=[(UIViewController *)[NSClassFromString(xibName) alloc] init];
    return control;
}

- (void)myAnimationPush{
//    CATransition *animation = [CATransition animation];
//    animation.duration = 0.5f;
//    animation.timingFunction = UIViewAnimationCurveEaseInOut;
//    animation.fillMode = kCAFillModeForwards;
//    animation.type = @"rippleEffect";
//    animation.subtype = kCATransitionFromRight;
//    [self.view.layer addAnimation:animation forKey:@"animation"];
}

- (void)myAnimationPop{
//    CATransition *animation = [CATransition animation];
//    animation.duration = 0.3f;
//    animation.timingFunction = UIViewAnimationCurveEaseInOut;
//    animation.fillMode = kCAFillModeForwards;
//    animation.type = @"cameraIris";
//    animation.subtype = kCATransitionFromRight;
//    [self.view.layer addAnimation:animation forKey:@"animation"];

}
@end



你可能感兴趣的:(页面传值)