views:

222

answers:

2

Hi Guys, here the following code is used to view the present modal view controller.

[[self navigationController] presentModalViewController:doctorListViewNavigationController animated:YES];

the close action is in the next view controller(DoctorListViewController). You can understand by seeing the following code I added now cleary. -(void)doctorsListAction { if(isFirst == YES) { [self getDoctorsListController]; [[self navigationController] presentModalViewController:doctorListViewNavigationController animated:YES];

}

}

-(void)getDoctorsListController { DoctorListViewController *doctorListViewController=[[DoctorListViewController alloc]init]; doctorListViewController.doctorList=doctorList; doctorListViewNavigationController=[[UINavigationController alloc]initWithRootViewController:doctorListViewController]; doctorListViewNavigationController.navigationBar.barStyle= UIBarStyleBlackOpaque; [doctorListViewController release];

code in next DoctorListViewContrller to dismiss the view. code for dismiss the ModalViewController. -(void)closeAction { [[self navigationController] dismissModalViewControllerAnimated:YES]; }

My problem is the dealloc method is not called then I am getting memory issue problems like object allocations, leaks..

  • (void)dealloc {

    [doctorList release]; [myTableView release]; [super dealloc]; }

A: 

How are you creating doctorListViewNavigationController?

xyzzycoder
A: 

Dealloc method is called when object is released same number of times, as it was retained. When you add doctorListView... (let's call it view) to navigationController (let's call it controller), the controller retains the view. And it was also retained during creation. That's why you should release this view twice: one time with dismissModalView... and one with direct release.

I mean something like this:

  [[self navigationController] presentModalViewController:doctorListViewNavigationController animated:YES];
  [doctorListViewNavigationController release];  // first time

...

- (void)closeAction {
  [[self navigationController] dismissModalViewControllerAnimated:YES];
               // second time
}
kpower
This is only correct if you own `doctorListViewNavigationController` already, for example, if you created it like so:`MYDoctorListViewNavigationController * doctorListViewNavigationController = [[doctorListViewNavigationController alloc] initWithNibname:@"something" bunlde:nil];` (admittedly, that is likely the case, but good to point out, as it seems to be where the question asker goes wrong).
Johan Kool
Thank you for your response, I edited more clearly to understand my problem
Madan Mohan
The close action is in other view i.e DoctorListView then how can i release it again.
Madan Mohan