Skip to content

Commit

Permalink
修复通过设置方法并且传入方法对应参数数组设置主题色失效的BUG
Browse files Browse the repository at this point in the history
修复通过设置方法并且传入方法对应参数数组设置主题色失效的BUG
  • Loading branch information
ko1o committed Feb 9, 2017
1 parent 08e1da4 commit a20d799
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion PYTheme/NSObject+PYThemeExtension.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ @implementation NSObject (PYThemeExtension)
static NSMutableArray<NSMapTable *> *_themeColorPool;
/** 当前主题色 */
static UIColor *_currentThemeColor;
/** 用于保存NSMapTable中的参数数组 */
static NSMutableDictionary *_parameterArrays;

/** 主题图片池 */
static NSMutableArray<id> *_themeImagePool;
Expand All @@ -38,6 +40,14 @@ - (NSMutableArray *)themeImagePool
return _themeImagePool;
}

- (NSMutableDictionary *)parameterArrays
{
if (!_parameterArrays) {
_parameterArrays = [NSMutableDictionary dictionary];
}
return _parameterArrays;
}

#pragma mark - performSelector 多参调用
- (id)py_performSelector:(SEL)selector withObjects:(const NSArray<id> *)objects
{
Expand Down Expand Up @@ -173,6 +183,9 @@ - (void)py_addToThemeColorPoolWithSelector:(SEL)selector objects:(NSArray *)obje
NSMapTable *mapTable = [NSMapTable mapTableWithKeyOptions:NSMapTableCopyIn valueOptions:NSMapTableWeakMemory];
[mapTable setObject:self forKey:pointSelectorString];
[mapTable setObject:objects forKey:PYTHEME_COLOR_ARGS_KEY];
// 目的:保住参数数组的生命周期 键:mapTable指针 值:参数数组
NSString *mapTablePointString = [NSString stringWithFormat:@"%p", mapTable];
[[self parameterArrays] setValue:objects forKey:mapTablePointString];
// 判断是否已经在主题色池中
for (NSMapTable *subMapTable in [[self themeColorPool] copy]) {
if ([[subMapTable description] isEqualToString:[mapTable description]]) { // 存在,直接返回
Expand Down Expand Up @@ -212,6 +225,8 @@ - (void)py_removeFromThemeColorPoolWithSelector:(SEL)selector
}
}
if([objectKey isEqualToString:pointSelectorString]) { // 存在,移除
// 移除参数数组
[_parameterArrays removeObjectForKey:[NSString stringWithFormat:@"%p", subMapTable]];
[[self themeColorPool] removeObject:subMapTable];
return;
}
Expand Down Expand Up @@ -288,7 +303,9 @@ - (void)py_setThemeColor:(UIColor *)color
break;
}
}
if (!key) { // 如果key为空,则mapTable 为空,移除mapTable
if (!key) { // 如果key为空,则对象被释放,移除mapTable
// 移除参数数组
[_parameterArrays removeObjectForKey:[NSString stringWithFormat:@"%p", mapTable]];
[_themeColorPool removeObject:mapTable];
}
// 取出对象
Expand Down

0 comments on commit a20d799

Please sign in to comment.