I have a tableViewController that I will present once in a while.
I have created it as a property, on .h
myTVC *myTable;
and
@property (nonatomic, retain) myTVC *myTable;
then, on .m I have synthesized it and created a getter
@synthesize myTable = _myTable;
and
- (myTVC *) myTable {
if (_myTable == nil) {
_myTable = [[myTVC alloc] init];
}
return _myTable;
}
when it is time to use I simply do
[self presentModalViewController:myTable animated:YES];
[myTable release];
as far as I thought, myTable’s getter would run at this point and allocate the tableViewController, but it is not running and the app crashes telling me that I am trying to present a nil tableViewController…
What am I missing? Thanks.
you need to do
self.myTableif you domyTableyou are asseccing your iVar that is callmyTableinto which your@propertyis not store, because you are doing this :@synthesize myTable = _myTable;which will create an iVar call_myTable.So you are doing 2 wrongs things in here.
To correct your code do the following :
remove this line :
myTVC *myTable;and do
[self presentModalViewController:self.myTable animated:YES];A 3rd thing is also strange in your code
I’m not sure why that line is there since you are storing your
controllerin a @property.and a 4th By the way
The default initializer for a UIViewController is the following
You can pass
nilif you don’t have a .xib to go with it.