I created a simple UIViewController with a custom init method like this:
-(id)initWithGroupNumber:(NSString *)groupNumber {
if ((self = [super init]) == nil) {
return nil;
}
self.levelGroup = groupNumber;
return self; }
levelGroup is a property written in the .h file
@property (nonatomic, retain) NSString *levelGroup;
When I call the method above this way:
LevelsViewController *lvc = [[LevelsViewController alloc]initWithGroupNumber:@"5"];
the controller is allocated but all the property inside are set to nil. I can’t understand why.
First of all when you deal with classes that have subclass of type mutable (e.g.
NSMutableString), usecopy.So, your property should become:
Then, inside the
UIViewControllersynthesize the propertyand in
initdo the following:As written in the memory management guide you should not use
self.insideinitand indealloc.Use your property
self.levelGroupto get or set the value.Remember to release in dealloc:
Hope it helps.