封装思路:
由于app多个地方需要未登录提示,导致代码重复。将相同的代码抽取出来放在一个公用类内,一句代码完成未登录提示跳转登录界面
.h文件
#import <Foundation/Foundation.h>
@interface LoginAlertTool : NSObject
+(void)alertLoginWithVC:(UIViewController*)viewController;
@end
.m文件
#import "LoginAlertTool.h"
#import "LoginVC.h"
@implementation LoginAlertTool
+(void)alertLoginWithVC:(UIViewController *)viewController {
if (![HXBSaveTool objectForKey:kUserID]) {
ZLAlertView *alert = [[ZLAlertView alloc]initWithTitle:@"温馨提示" message:@"该功能需登录后使用"];
[alert addBtnTitle:@"好的" action:^{
}];
[alert addBtnTitle:@"立即登录" action:^{
LoginVC *vc = [[LoginVC alloc]initWithNibName:@"LoginVC" bundle:nil];
[viewController.navigationController pushViewController:vc animated:YES];
}];
[alert showAlertWithSender:viewController];
return;
}
}
@end