Commit 91445fa1 authored by 汪洋's avatar 汪洋

被present的controller也可以自动获取referer与referrerId。referer改为可以set

parent 0ac7c414
......@@ -17,24 +17,33 @@
*
* @brief 取当前导航栈中当前VC的上级VC,如果该VC存在,就获取他的pageName
*
* @return 前一页的pageName
*
* @since 5.9.1
*/
- (void)initReferer {
if ([self isKindOfClass:[UIViewController class]]) {
NSArray *navigationPool = ((UIViewController *)self).navigationController.viewControllers;
NSInteger refererIndex = navigationPool.count - 2;
if (refererIndex < 0 ) {
return ;
// 只有不为空,且是controller的情况下才自动获取
if (self.referer == nil && [self isKindOfClass:[UIViewController class]]) {
// 分present与navigation两种情况
UIViewController *me = (UIViewController *)self;
if (me.presentingViewController != nil) {
objc_setAssociatedObject(self, @selector(referer), me.presentingViewController.pageName, OBJC_ASSOCIATION_COPY);
} else {
NSArray *navigationPool = ((UIViewController *)self).navigationController.viewControllers;
NSInteger refererIndex = navigationPool.count - 2;
if (refererIndex < 0 ) {
return ;
}
UIViewController *controller = navigationPool[refererIndex];
objc_setAssociatedObject(self, @selector(referer), controller.pageName, OBJC_ASSOCIATION_COPY);
}
UIViewController *controller = navigationPool[refererIndex];
objc_setAssociatedObject(self, @selector(referer), controller.pageName, OBJC_ASSOCIATION_COPY);
} else {
objc_setAssociatedObject(self, @selector(referer), @"", OBJC_ASSOCIATION_COPY);
}
}
- (void)setReferer:(NSString *)referer {
objc_setAssociatedObject(self, @selector(referer), referer, OBJC_ASSOCIATION_COPY);
}
- (NSString *)referer
{
NSString *referer = objc_getAssociatedObject(self, @selector(referer));
......@@ -73,15 +82,22 @@
}
- (void)initReferrerIdIfNil {
// 只有不为空,且是controller的情况下才自动获取
if (self.referrerId == nil && [self isKindOfClass:[UIViewController class]]) {
NSArray *navigationPool = ((UIViewController *)self).navigationController.viewControllers;
NSInteger refererIdIndex = navigationPool.count - 2;
if (refererIdIndex < 0) {
objc_setAssociatedObject(self, @selector(referrerId), @"", OBJC_ASSOCIATION_COPY);
// 分present与navigation两种情况
UIViewController *me = (UIViewController *)self;
if (me.presentingViewController != nil) {
objc_setAssociatedObject(self, @selector(referrerId), me.presentingViewController.businessId, OBJC_ASSOCIATION_COPY);
} else {
UIViewController *controller = navigationPool[refererIdIndex];
NSString *preBusinessId = controller.businessId;
objc_setAssociatedObject(self, @selector(referrerId), preBusinessId, OBJC_ASSOCIATION_COPY);
NSArray *navigationPool = ((UIViewController *)self).navigationController.viewControllers;
NSInteger refererIdIndex = navigationPool.count - 2;
if (refererIdIndex < 0) {
objc_setAssociatedObject(self, @selector(referrerId), @"", OBJC_ASSOCIATION_COPY);
} else {
UIViewController *controller = navigationPool[refererIdIndex];
NSString *preBusinessId = controller.businessId;
objc_setAssociatedObject(self, @selector(referrerId), preBusinessId, OBJC_ASSOCIATION_COPY);
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment