Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.0.7 更新日志 #19

Open
xaoxuu opened this issue May 29, 2017 · 0 comments
Open

0.0.7 更新日志 #19

xaoxuu opened this issue May 29, 2017 · 0 comments

Comments

@xaoxuu
Copy link
Owner

xaoxuu commented May 29, 2017

UIImageViewWithImageNamed

根据图片名快速创建imageview

UIImageViewWithImageNamed(NSString *name);

更灵活的popViewController

有时候你可能会需要pop到上上一层控制器,或者根控制器下的第二个控制器等等,

有了这两个方法,你可以pop到同一NavigationController下的任意一个控制器。

/**
 pop到指定viewController

 @param index 从rootVC开始向后数的index,rootVC为0
 */
- (void)ax_popToViewControllerWithIndexFromRoot:(NSUInteger)index;

/**
 pop到指定viewController

 @param index 从当前viewController开始向前数的index,当前VC为0
 */
- (void)ax_popToViewControllerWithIndexFromSelf:(NSUInteger)index;

详细使用请见 #14

NSUserDefaults+

封装了NSUserDefaults,对读取的值可能为空和不为空的情况分类处理,更安全和方便。例如:

// @xaoxuu: 将用户头像缓存到userdefault
[NSUserDefaults ax_setData:UIImagePNGRepresentation(image) forKey:@"avatar"];
// @xaoxuu: 从userdefault读取图片
[NSUserDefaults ax_readDataForKey:@"avatar" completion:^(NSData * _Nonnull data) {
    // @xaoxuu: 读取到值
    UIImage *image = [UIImage imageWithData:data];
    avatar.image = image;
} fail:^(NSError * _Nonnull error) {
    // @xaoxuu: 读取不到值
    AXLogError(error);
}];

详细使用请见 #13

代码冷却 : cooldown

我个人认为设计合理的代码是用不到这个机制的,

但是不能保证我们永远不需要,所以我就提供了这个冷却机制。

优点:执行代码像放技能一样,可以强行打破死循环、避免死循环、避免过高频率访问某一资源、从一定程度上缓解了内存、CPU压力。

缺点:治标不治本,最好是找出会产生问题的代码,从根源上解决问题。

使用示例:

// @xaoxuu: 重新获取数据源并刷新tableView
- (void)reloadDataSourceAndTableView{
    [NSBlockOperation ax_delay:0 cooldown:2 token:@"reload data source and refresh table view" performInMainQueue:^{
        [self.dataList removeAllObjects];
        [self reloadTableView];
    }];
}

详细使用请见 #15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant