views:

250

answers:

0

Hi Guys, This is PresentModelViewController, when click a button i will get this "DoctorListViewController" controller from down. object allocation are not releasing in this controller specially in cellForRowAtIndexPath delegate method. UITableViewCell and two labels allocated in this is not releasing. In the previous view The allocation count of this " UITableViewCell and two labels" is increasing.Also the dealloc method in this view controller is not called when I dismiss the modelviewcontrller, that is way I have released in the close method.

please suggest me a right solution Thank you.

#import "DoctorListViewController.h"

- (id)init
{
    if (self = [super init])
    {
        self.title=@"Doctors List";
        UIView *myView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
        myView.autoresizingMask=YES;
        [myView setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
        myTableView=nil;
        myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0,320,420) style:UITableViewStylePlain];
        myTableView.delegate = self;
        myTableView.dataSource=self;
        [myTableView setSectionFooterHeight:5];
        [myTableView setSectionHeaderHeight:15];
        [myTableView setSeparatorColor:[UIColor greenColor]];
        [myView addSubview: myTableView];

        UIBarButtonItem *addButton = [[UIBarButtonItem alloc]initWithTitle:@"Close" 
                                            style:UIBarButtonItemStyleBordered 
                                            target:self 
                                            action:@selector(closeAction)];
        self.navigationItem.leftBarButtonItem = addButton;
        [addButton release];
        self.view = myView;
         [myView release];

    }
    return self;
}

-(void)closeAction
{
    printf("\n hai i am in close action*******************************");
    [doctorList release];
[myTableView release];
    myTableView=nil;
    printf("\n myTableView retainCount :%d",[myTableView retainCount]);
    [[self navigationController] dismissModalViewControllerAnimated:YES];       
}

#pragma mark methods for dataSource and delegate

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = (UITableViewCell *)[myTableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
    if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"MyIdentifier"]autorelease];


        UIView* elementView =  [ [UIView alloc] initWithFrame:CGRectMake(5,5,300,480)];
        elementView.tag = 0;
        [cell.contentView addSubview:elementView];
        [elementView release];
    }
    UIView* elementView  = [cell.contentView viewWithTag:0];
    for(UIView* subView in elementView.subviews)
    {
        [subView removeFromSuperview];
    }
    if(indexPath.row != [doctorList count])
    {
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            Doctor *obj= [doctorList objectAtIndex:indexPath.row];

        UILabel *firstNameLabel =[[[UILabel alloc] initWithFrame:CGRectMake(5,2,300,15)]autorelease];
        [firstNameLabel setFont:[UIFont boldSystemFontOfSize:12]];
        firstNameLabel.textColor = [UIColor blackColor];        
        firstNameLabel.textColor =[UIColor blackColor];
        firstNameLabel.numberOfLines = 0;
        firstNameLabel.tag=1;
        firstNameLabel.backgroundColor = [UIColor clearColor];
        NSString *str=obj.firstName;
        str=[str stringByAppendingString:@" "];
        str=[str stringByAppendingString:obj.lastName];
        firstNameLabel.text=str;
        [elementView addSubview:firstNameLabel];
        //[firstNameLabel release];
        firstNameLabel=nil;

        UILabel *streetLabel =[[[UILabel alloc] initWithFrame:CGRectMake(5,20,300,15)]autorelease];
        [streetLabel setFont:[UIFont systemFontOfSize:12]];
        streetLabel.textColor = [UIColor blackColor];
        streetLabel.numberOfLines = 0;
        streetLabel.tag=2;
        streetLabel.backgroundColor = [UIColor clearColor];
        streetLabel.text=obj.streetAddress;
        [elementView addSubview:streetLabel];
        //[streetLabel release];
        streetLabel=nil;

        printf("\n retainCount count of firstNameLabel  %d",[firstNameLabel retainCount]);
        printf("\n retainCount count of streetLabel  %d",[streetLabel retainCount]);
        printf("\n retainCount count of cell  %d",[cell retainCount]);


    }
    return cell;
}
- (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    [myTableView deselectRowAtIndexPath:indexPath animated:YES];
    DoctorDetailsViewController *doctorDetailsViewController=[[DoctorDetailsViewController alloc]init];
    Doctor *obj= [doctorList objectAtIndex:indexPath.row];
    BOOL isList=YES;
    doctorDetailsViewController.isList=isList;
    doctorDetailsViewController.doctorObj=obj;
    [[self navigationController] pushViewController:doctorDetailsViewController animated:YES];
    [doctorDetailsViewController release];
}

- (void)dealloc 
{
    printf("\n hai i am in dealloc of Doctor list view contrller");
    //[doctorList release];
    //[myTableView release];
    [super dealloc];
}

@end