开发者

UIView Does Not Rotate

开发者 https://www.devze.com 2022-12-12 14:35 出处:网络
I have the following code in a UIViewController Notepad *notepad = [[Notepad alloc] initForNewTopLevelTask:0 andDAO:self.dao];

I have the following code in a UIViewController

Notepad *notepad = [[Notepad alloc] initForNewTopLevelTask:0 andDAO:self.dao];

[self.navigationController pushViewController:notepad animated:YES];
[notepad release];

The initForNewTopLevelTask:andDAO: method is:

- (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;
}

When I rotate the view nothing happens, it does not rotate. If I change the UIViewController line to:

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

It rotates fine!

The view is not part of a Tab Controller and I have implemented:

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrient开发者_StackOverflow社区ation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return YES;
}


you should always call up to a parent class init method in your own init methods. Atleast for any object that is at some point extending from NSObject.

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

Change your init function to:

- (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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消