views:

228

answers:

1

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)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return YES;
}
+1  A: 

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%5Fref/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;
}
Eld
thank you so so so much!
Neil Foley