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


     

  • 相关阅读:
    ConcurrentHashMap总结
    HashMap在多线程环境下操作可能会导致程序死循环
    oracle数据库的 to char 和to date 区别(时间格式化)
    SQL中的cast()函数用法
    常见的垃圾收集器有3类-java面试一
    mybatis中sql引用
    mysql find_in_set 查询
    用Redis实现微博关注关系的分析
    C#与C++相比较之STL篇(续一)
    Vite2.0 入门
  • 原文地址:https://www.cnblogs.com/wqxlcdymqc/p/3214414.html
Copyright © 2011-2022 走看看