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


 

posted @ 2013-07-25 15:15  星烨痕  阅读(540)  评论(0编辑  收藏  举报