#import <UIKit/UIKit.h>

#import "YQZMutableArray.h"

@interface YQZViewController : UIViewController

@property (nonatomic, strong) NSString *kTitle;

//保存当前正在运行的http请求

@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 dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,[UIFont boldSystemFontOfSize:20],UITextAttributeFont,[NSValue valueWithUIOffset:UIOffsetZero], UITextAttributeTextShadowOffset,nil];

//    } else if (kdSystemVersion >= 7.0)

//    {

//

//    }

}

- (void)dealloc

{

NSLog(@"%@ has dealloc",[NSString stringWithUTF8String: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:@"打电话"] forState:UIControlStateNormal];

[button setImage:[UIImage imageNamed:@"打电话"] 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

Viewcontroller基类的更多相关文章

  1. 【iOS】 含tableView的ViewController基类的实现

    上篇博客写了ViewController的基类的实现,这篇博客主要写在BaseViewController的基础上实现一个含tableView控件的基类的实现,主要给包含tableView的页面来继承 ...

  2. iOS控制器之基类设计

    题记 在进入新公司后.经过这一个月的重构项目,终于把项目做到了个人相对满意的程度(还有一种不满意的叫老板的需求,提过多次意见也没用= =!).在这次重构中按照以前的思路设计出了个人觉得比较适用的一个基 ...

  3. 无线客户端框架设计(3):基类的设计(iOS篇)

    本文代码:YoungHeart-Chapter-03.zip 没有基类的App都不是好App. 因为iOS使用的是mvc模式的开发模式,所以,业务逻辑基本都在每个页面相应的ViewController ...

  4. 【iOS】UIViewController基类的实现

    继承是面向对象编程语言的三大特性之一,写好基类会给App的开发带来极大的方便.在iOS开发中,一般一个页面就对应一个ViewController,ViewController在开发中用的也很多,写一个 ...

  5. [Swift实际操作]九、完整实例-(5)创建BaseViewController作为控制器的基类

    本文将给项目中的所有视图控制器,创建一份基类.该基类用来定义一些共用的属性和方法. 首先在用来放置视图控制器类的文件夹上点击鼠标右键,打开右键 菜单. 选择[New File]创建文件选项. 在弹出的 ...

  6. 写个Fragment方便的抽象基类 BaseFragment

    package com.zb.zhihuianyang.base; import android.app.Activity; import android.os.Bundle; import andr ...

  7. 【C++】继承(虚基类)

    类的继承与派生 面向对象技术强调软件的可重用性,这种重用性通过继承机制来实现.而在类的继承过程中,被重用的原有类称为基类,新创建的类称为派生类.派生类定义语法格式如下: class <派生类名& ...

  8. 虚函数的使用 以及虚函数与重载的关系, 空虚函数的作用,纯虚函数->抽象类,基类虚析构函数使释放对象更彻底

    为了访问公有派生类的特定成员,可以通过讲基类指针显示转换为派生类指针. 也可以将基类的非静态成员函数定义为虚函数(在函数前加上virtual) #include<iostream> usi ...

  9. lua中基类和“继承机制”

    基类:基类定义了所有对于派生类来说普通的属性和方法,派生类从基类继承所需的属性和方法,且在派生类中增加新的属性和方法. 继承:继承是C++语言的一种重要机制,它允许在已定义的类的基础上产生新类. lu ...

随机推荐

  1. CentOS虚拟机通过主机网络上网

    0 环境简介 环境如下: (1)宿主机为WIN7系统,连接内网,同时通过网关服务器上外网: (2)虚拟机为VMWare12下的CentOS7系统. 宿主机通过WIFI方式上外网的配置方法,参考本人另一 ...

  2. oracle 查询及删除重复记录的SQL语句

    查询及删除重复记录的SQL语句 1.查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断 select * from 表 where Id in (select Id from 表 group ...

  3. win32常用代码整理

    1.ShellExecute [Use ShellAPI] ShellExecute(Handle, 'open', 'http://www.cnblogs.com/lovelp/', nil, ni ...

  4. centos 安装webbench 用于web压力测试

    1.WebBench安装: yum install ctags(先安装依赖库) mkdir /usr/local/man (创建一个目录不然会报错) wget http://home.tiscali. ...

  5. VMware S/4 HANA OP 1511虚拟机下载,64G内存限制解决方案

    http://www.itpub.net/thread-2057212-1-1.html S4 HANA OP 1511 Scale Out

  6. IE11浏览器中的My97日历控件刷新后无法打开问题解决办法

    IE11浏览器中的My97日历控件刷新后无法打开问题解决办法   IE11浏览器中的My97日历控件刷新后无法打开问题解决办法:(谷歌浏览器下正常.IE11失效) 解决办法:1:找到WdatePick ...

  7. Sharepoint2013搜索学习笔记之创建搜索服务(二)

    第一步,进入管理中心,点击管理服务器上的服务 第二步,在服务器上选择需要承载搜索服务的服务器,并启动服务列表上的sharepoint server search 第三步,从管理中心进入管理服务应用程序 ...

  8. PhpStorm之三种视图模式

    全屏模式 允许你使用整个屏幕编写代码,在视图中移除了所有菜单,同样也移除了操作系统控制栏.然而,你可以继续使用右键菜单和快捷键.当你把鼠标悬停到屏幕顶部时仍然可以看到主菜单. 演示模式 这个模式和全屏 ...

  9. Unity3D 自动添加Fbx Animation Event

    http://blog.csdn.net/aa20274270/article/details/52528449 using UnityEngine; using System.Collections ...

  10. Node.js 内置模块crypto加密模块(2) AES

    AES:高级加密标准 ( Advanced Encryption Standard ) AES是一种对称加密算法:加密需要密钥,且加密密钥和解密密钥相同 下面是AES加密的Node实现: " ...