2009-11-28 52 views
0

我曾經在一個UIViewController的UIView不轉

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

回答

1

你應該總是在自己的init方法調用父類init方法。至少對於任何從NSObject延伸的對象。

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

更改您的初始化函數:

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

謝謝你這麼這麼這麼多! – 2009-11-28 18:54:31