封裝思路:
由于app多個地方需要未登錄提示犁钟,導(dǎo)致代碼重復(fù)。將相同的代碼抽取出來放在一個公用類內(nèi)泼橘,一句代碼完成未登錄提示跳轉(zhuǎn)登錄界面
.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