代码之家  ›  专栏  ›  技术社区  ›  Neil Foley

uiview不旋转

  •  0
  • Neil Foley  · 技术社区  · 15 年前

    我在uiviewcontroller中有以下代码

    Notepad *notepad = [[Notepad alloc] initForNewTopLevelTask:0 andDAO:self.dao];
    
    [self.navigationController pushViewController:notepad animated:YES];
    [notepad release];
    

    initfornewtopleveltask:和dao:方法是:

    - (id) initForNewTopLevelTask:(int) theTableSize andDAO:(DAO*) aDAO {
        self.dao = aDAO;
        tableSize = [[NSNumber alloc] initWithInt:theTableSize];
        self.isNew = [NSNumber numberWithBool:YES];
        self.isSubtask =[NSNumber numberWithBool:NO];
            return self;
    }
    

    当我旋转视图时,没有发生任何事情,它不会旋转。如果我将uiviewcontroller行更改为:

    Notepad *notepad = [[Notepad alloc] init];
    

    它旋转得很好!

    该视图不是选项卡控制器的一部分,我已经实现了:

    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations
        return YES;
    }
    
    1 回复  |  直到 15 年前
        1
  •  1
  •   Eld    15 年前

    您应该总是在自己的init方法中调用父类init方法。至少对于在某个点上从nsObject扩展的任何对象。

    http://developer.apple.com/iphone/library/documentation/cocoa/Conceptual/ObjectiveC/Articles/ocAllocInit.html#//apple_ref/doc/uid/TP30001163-CH22-SW4

    将init函数更改为:

    - (id) initForNewTopLevelTask:(int) theTableSize andDAO:(DAO*) aDAO {
        if ( self = [super init] ) {
        self.dao = aDAO;
        tableSize = [[NSNumber alloc] initWithInt:theTableSize];
        self.isNew = [NSNumber numberWithBool:YES];
        self.isSubtask =[NSNumber numberWithBool:NO];
        }
        return self;
    }