我在UIViewController中有以下代码
Notepad *notepad = [[Notepad alloc] initForNewTopLevelTask:0 andDAO:self.dao];
[self.navigationController pushViewController:notepad animated:YES];
[notepad release];
initForNewTopLevelTask:andDAO:方法是:
- (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;
}
答案 0 :(得分:1)
您应该始终在自己的init方法中调用父类init方法。至少从NSObject扩展的任何对象。
将您的初始化函数更改为:
- (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;
}