Viewcontroller base class, viewcontroller Base
# Import <UIKit/UIKit. h>
# Import "YQZMutableArray. h"
@ Interface YQZViewController: UIViewController
@ Property (nonatomic, strong) NSString * kTitle;
// Save the currently running http Request
@ Property (nonatomic, strong) YQZMutableArray * httpRequestArray;
-(Void) addBackBtnToHomePage;
-(Void) addLeftBackBtn;
-(UIButton *) addRightTextButtonWithText :( NSString *) buttonText action :( SEL) action;
-(UIButton *) addRightImageButtonWithImageName :( NSString *) imageNamed action :( SEL) action;
-(UIButton *) addLeftTextButtonWithText :( NSString *) buttonText action :( SEL) action;
-(Void) back;
-(Void) backToHomepage;
-(Void) addMakeCall;
-(Void) loadTopData;
-(Void) showLogin;
-(Void) cancelHttpRequest;
@ End
. M
# Import "YQZViewController. h"
# Import "YQZAppDelegate. h"
# Import "YQZLoginViewController. h"
# Import "SDWebImageManager. h"
# Import "YQZImageCache. h"
# Import "AFHttpClient. h"
@ Interface YQZViewController ()
@ End
@ Implementation YQZViewController
-(Id) initWithNibName :( NSString *) nibNameOrNil bundle :( NSBundle *) nibBundleOrNil
{
Self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil];
If (self)
{
Self. httpRequestArray = [[YQZMutableArray alloc] init];
}
Return self;
}
-(Void) viewDidLoad
{
[Super viewDidLoad];
If (kdSystemVersion> = 7.0f ){
[Self. navigationController. navigationBar setTranslucent: NO];
[Self. navigationController. view setBackgroundColor: kYQZBorderGrayLightColor];
[Self setExtendedLayoutIncludesOpaqueBars: YES];
[Self setAutomaticallyAdjustsScrollViewInsets: YES];
[Self setModalTransitionStyle: UIModalTransitionStyleCoverVertical];
[Self setModalPresentationStyle: UIModalPresentationFullScreen];
[Self setEdgesForExtendedLayout: UIRectEdgeAll];
Self. edgesForExtendedLayout = UIRectEdgeNone;
}
// If (kdSystemVersion <7.0 ){
// Self. navigationController. navigationBar. titleTextAttributes = [NSDictionary attributes: [UIColor whiteColor], attributes, [UIFont boldSystemFontOfSize: 20], attributes, [NSValue valueWithUIOffset: UIOffsetZero], identifier, nil];
//} Else if (kdSystemVersion >=7.0)
//{
//
//}
}
-(Void) dealloc
{
NSLog (@ "% @ has dealloc", [NSString stringwithuf8string: object_getClassName (self)]);
}
-(Void) loadTopData
{
}
-(Void) showLogin
{
If ([YQZLoginViewController canAutoLogin])
{
[Self autoLogin];
} Else {
[Self manualLogin];
}
}
-(Void) autoLogin
{
[YQZSetting sharedInstance]. loginStatus = LoginStatusLogOut;
YQZLoginViewController * autoLoginViewController = [[YQZLoginViewController alloc] initWithNibName: @ "YQZLoginViewController" bundle: nil];
[AutoLoginViewController autoLogin];
}
-(Void) manualLogin
{
YQZLoginViewController * loginViewController = [[YQZLoginViewController alloc] initWithNibName: @ "YQZLoginViewController" bundle: nil];
LoginViewController. delegate = self;
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController: loginViewController];
// [Self. navigationController presentViewController: navigationController animated: TRUE completion: NULL];
YQZAppDelegate * delegate = (YQZAppDelegate *) [UIApplication sharedApplication]. delegate;
[Delegate. window. rootViewController presentViewController: navigationController animated: YES completion: nil];
}
-(Void) didReceiveMemoryWarning
{
[Super didReceiveMemoryWarning];
[[SDWebImageManager sharedManager] imageCache] clearMemory];
[[YQZImageCache sharedInsance] clearCachedImages];
}
-(Void) back
{
[Self. view endEditing: YES];
[Self cancelHttpRequest];
[Self. navigationController popViewControllerAnimated: YES];
}
-(Void) addMakeCall
{
UIButton * button = [[UIButton alloc] initWithFrame: CGRectMake (0, 0, 30, 30)];
Button. backgroundColor = [UIColor clearColor];
[Button setImage: [UIImage imageNamed: @ "call"] forState: UIControlStateNormal];
[Button setImage: [UIImage imageNamed: @ "call"] forState: UIControlStateHighlighted];
Button. imageEdgeInsets = kNavigationRightButtonInSet;
[Button addTarget: self action: @ selector (makeCall) forControlEvents: UIControlEventTouchUpInside];
Self. navigationItem. rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: button];
}
-(Void) makeCall
{
NSString * telStr = [NSString stringWithFormat: @ "tel: // % @", kCompanyPhone];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: telStr];
[MobClick event: @ "Other_CallTel"];
}
-(Void) backToHomepage
{
[Self. navigationController popViewControllerAnimated: YES];
}
-(Void) addLeftBackBtn
{
UIBarButtonItem * negativeSpacer = [UIBarButtonItem alloc]
InitWithBarButtonSystemItem: UIBarButtonSystemItemFixedSpace
Target: nil action: nil];
If (kdSystemVersion> = 7.f ){
NegativeSpacer. width =-10;
}
UIButton * button = [[UIButton alloc] initWithFrame: CGRectMake (0, 0, 30, 30)];
Button. backgroundColor = [UIColor clearColor];
[Button setImage: [UIImage imageNamed: @ "back"] forState: UIControlStateNormal];
[Button setImage: [UIImage imageNamed: @ "back_h"] forState: UIControlStateHighlighted];
[Button addTarget: self action: @ selector (back) forControlEvents: UIControlEventTouchUpInside];
UIBarButtonItem * backNavigationItem = [[UIBarButtonItem alloc] initWithCustomView: button];
Self. navigationItem. leftBarButtonItems = @ [negativeSpacer, backNavigationItem];
}
-(Void) addBackBtnToHomePage
{
UIButton * button = [[UIButton alloc] initWithFrame: CGRectMake (0, 0, 30, 30)];
Button. backgroundColor = [UIColor clearColor];
[Button setImage: [UIImage imageNamed: @ "back"] forState: UIControlStateNormal];
[Button setImage: [UIImage imageNamed: @ "back_h"] forState: UIControlStateHighlighted];
[Button addTarget: self action: @ selector (backToHomepage) forControlEvents: UIControlEventTouchUpInside];
Self. navigationItem. leftBarButtonItem = nil;
Self. navigationItem. leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: button];
}
-(UIButton *) addRightTextButtonWithText :( NSString *) buttonText action :( SEL) action
{
UIButton * textButton = [[UIButton alloc] initWithFrame: CGRectMake (0, 0, 70, 44)];
TextButton. backgroundColor = [UIColor clearColor];
[TextButton setTitle: buttonText forState: UIControlStateNormal];
TextButton. titleLabel. font = [UIFont systemFontOfSize: kNavigationButtonFontSize];
If (buttonText. length = 4 ){
If (kdSystemVersion> = 7.f ){
TextButton. titleEdgeInsets = UIEdgeInsetsMake (0, 0, 0,-15 );
}
} Else {
If (kdSystemVersion> = 7.f ){
TextButton. titleEdgeInsets = UIEdgeInsetsMake (0, 0, 0,-48 );
}
}
[TextButton addTarget: self action: action forControlEvents: UIControlEventTouchUpInside];
Self. navigationItem. rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: textButton];
Return textButton;
}
-(UIButton *) addRightImageButtonWithImageName :( NSString *) imageName action :( SEL) action
{
UIButton * imageButton;
If (DEVICE_IS_IPHONE6Plus | DEVICE_IS_IPHONE6PlusBig ){
ImageButton = [[UIButton alloc] initWithFrame: CGRectMake (0, 0, 44, 44)];
}
Else {
ImageButton = [[UIButton alloc] initWithFrame: CGRectMake (0, 0, 30, 30)];
}
ImageButton. backgroundColor = [UIColor clearColor];
[ImageButton setImage: [UIImage imageNamed: imageName] forState: UIControlStateNormal];
[ImageButton setImage: [UIImage imageNamed: imageName] forState: UIControlStateHighlighted];
[ImageButton setImageEdgeInsets: kNavigationRightButtonInSet];
ImageButton. titleLabel. font = [UIFont systemFontOfSize: kNavigationButtonFontSize];
[ImageButton addTarget: self action: action forControlEvents: UIControlEventTouchUpInside];
Self. navigationItem. rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: imageButton];
Return imageButton;
}
-(UIButton *) addLeftTextButtonWithText :( NSString *) buttonText action :( SEL) action
{
UIButton * textButton = [[UIButton alloc] initWithFrame: CGRectMake (0, 0, 70, 44)];
TextButton. backgroundColor = [UIColor clearColor];
[TextButton setTitle: buttonText forState: UIControlStateNormal];
TextButton. titleLabel. font = [UIFont systemFontOfSize: kNavigationButtonFontSize];
[TextButton. titleLabel setTextAlignment: NSTextAlignmentLeft];
If (buttonText. length = 4 ){
If (kdSystemVersion> = 7.f ){
TextButton. titleEdgeInsets = UIEdgeInsetsMake (0,-15, 0, 0 );
}
} Else {
If (kdSystemVersion> = 7.f ){
TextButton. titleEdgeInsets = UIEdgeInsetsMake (0,-48, 0, 0 );
}
}
[TextButton addTarget: self action: action forControlEvents: UIControlEventTouchUpInside];
Self. navigationItem. leftBarButtonItem = nil;
Self. navigationItem. leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: textButton];
Return textButton;
}
-(Void) cancelHttpRequest
{
For (id opertion in self. httpRequestArray ){
If ([opertion isKindOfClass: [AFHTTPRequestOperation class]) {
[Opertion cancel];
}
}
[Self. httpRequestArray removeAllObjects];
}
@ End