zoukankan      html  css  js  c++  java
  • IOS:兼容ios6和低版本

    viewDidUnload在ios6开始被弃用了,所以我们在这里处理内存警告的这类问题,这个时候我们就要把相应的处理放在

    didReceiveMemoryWarning中。

    - (void)didReceiveMemoryWarning 

    {

        [super didReceiveMemoryWarning];

        sortedNames nil;

        sortedValues nil;

    }

    但是如果我们新老版本都要支持的话,那么还需要再加些东西进去。

    - (void)didReceiveMemoryWarning 

    {

        [super didReceiveMemoryWarning];

        if([self isViewLoaded] && self.view.window == nil

        {

            self.view = nil;

        }

        sortedNames = nil;

        sortedValues = nil;

    }

    在ios6中还有一个比较重要的方法被弃用了,那就是

    shouldAutorotateToInterfaceOrientation

    这个方法用来控制屏幕的旋转,所以在ios6上,我们就需要用

    - (BOOL)shouldAutorotate
    {
           //return;
    }
    - (NSUInteger)supportedInterfaceOrientations
    {
       // return 
    }

    但是我们往往还要支持低版本的,所以在程序中,我们就需要保留之前的方法。

    但如果想要控制“UINavigationController”直接在Contoller中使用这个方法,将会不起作用,原因是ios6中“UINavigationController”并不支持- (BOOL)shouldAutorotate、- (NSUInteger)supportedInterfaceOrientations个方法,如果您想要控制其旋转,必须为其添加一个category,使其支持这个三个方法。

    @implementation UINavigationController (SupportIOS6)
     
    -(BOOL)shouldAutorotate
    {
        return [[self.viewControllers lastObject] shouldAutorotate];
    }
     
    -(NSUInteger)supportedInterfaceOrientations
    {
        return [[self.viewControllers lastObject] supportedInterfaceOrientations];
    }
     
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; 
    }
    @end


     

  • 相关阅读:
    Codeforces #250 (Div. 2) B. The Child and Set
    linux下又一次定位svn url方法
    查看hive版本号
    好947 Mybatis 配置resultMap 带參数查询Map 注意selectOne数据库返回结果一条数据库 否则会报错
    csdn加入暂时会话功能
    第二十五天 慵懒的投射在JDBC上的暖阳 —Hibernate的使用(四)
    lzma 知识点滴
    golang 登录
    docker入门
    创建和管理表(10)
  • 原文地址:https://www.cnblogs.com/wqxlcdymqc/p/3214414.html
Copyright © 2011-2022 走看看