mercredi 3 décembre 2014

How to clear content on a collection view layout ios

I am developing a iOS app in which i am using a customized collection view. in the menu bar it has list of 3 controller 1, 2, 3. when i select 2 i want to create a new collection view layout and clear the previous one . Is it possible to clear data from previous collection view layout. Collection view is being created programmatically iOS.


This is my piece of code.




  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{


    NSLog(@"indexpath : %ld",(long)indexPath.row);


    if(((long)indexPath.row==0) && (indexPath.section==0)){ HelpController *three=[[HelpController alloc] initWithNibName:@"HelpController" bundle:nil]; [ self presentViewController:three animated:YES completion:nil]; // [self.navigationController pushViewController:three animated:YES]; NSLog(@"Help");


    } if(((long)indexPath.row==1) && (indexPath.section==0)){



    backupController *bckup=[[backupController alloc]initWithNibName:@"backupController" bundle:nil];
    [self presentViewController:bckup animated:YES completion:nil];
    // [self.navigationController pushViewController:bckup animated:YES];
    NSLog(@"BackUp");


    } if(((long)indexPath.row==2) && (indexPath.section==0)){ NSLog(@"Children"); [self.navigationController dismissViewControllerAnimated:YES completion:nil];


    } if(((long)indexPath.row==3) && (indexPath.section==0)){ AboutusController *three=[[AboutusController alloc] initWithNibName:@"AboutusController" bundle:nil]; [ self presentViewController:three animated:YES completion:nil]; NSLog(@"AboutUS");


    } if(((long)indexPath.row==4) && (indexPath.section==1)){ AddChildViewController *three=[[AddChildViewController alloc] initWithNibName:@"AddChildViewController" bundle:nil]; [ self.navigationController pushViewController:three animated:YES]; NSLog(@"AboutUS");


    } if(((long)indexPath.row==0) && (indexPath.section==1)){



    NSString *savedValue = [[NSUserDefaults standardUserDefaults]
    stringForKey:@"firstchild"];
    [[NSUserDefaults standardUserDefaults] setObject:savedValue forKey:@"childname"];

    [[childDBHelper sharedInstance] createDatabase];

    AddChildViewController *add =[[AddChildViewController alloc]initWithNibName:@"AddChildViewController" bundle:nil];
    [add navigatenext];
    // [self.navigationController popToRootViewControllerAnimated:];
    [self viewWillAppear:YES];
    [self viewDidLoad];


    } if(((long)indexPath.row==1) && (indexPath.section==1)){



    NSString *savedValue = [[NSUserDefaults standardUserDefaults]
    stringForKey:@"secondchild"];
    [[NSUserDefaults standardUserDefaults] setObject:savedValue forKey:@"childname"];

    [[childDBHelper sharedInstance] createDatabase];

    AddChildViewController *add =[[AddChildViewController alloc]initWithNibName:@"AddChildViewController" bundle:nil];
    [add navigatenext];


    // [self.navigationController popToRootViewControllerAnimated:]; [self viewWillAppear:YES]; [self viewDidLoad]; } if(((long)indexPath.row==2) && (indexPath.section==1)){



    NSString *savedValue = [[NSUserDefaults standardUserDefaults]
    stringForKey:@"thirdchild"];
    [[NSUserDefaults standardUserDefaults] setObject:savedValue forKey:@"childname"];

    [[childDBHelper sharedInstance] createDatabase];

    AddChildViewController *add =[[AddChildViewController alloc]initWithNibName:@"AddChildViewController" bundle:nil];
    [add navigatenext];
    // [self.navigationController popToRootViewControllerAnimated:];
    [self viewWillAppear:YES];
    [self viewDidLoad];


    } if(((long)indexPath.row==3) && (indexPath.section==1)){



    NSString *savedValue = [[NSUserDefaults standardUserDefaults]
    stringForKey:@"fourthchild"];
    [[NSUserDefaults standardUserDefaults] setObject:savedValue forKey:@"childname"];

    [[childDBHelper sharedInstance] createDatabase];

    AddChildViewController *add =[[AddChildViewController alloc]initWithNibName:@"AddChildViewController" bundle:nil];
    [add navigatenext];
    // [self.navigationController popToRootViewControllerAnimated:];
    [self viewWillAppear:YES];
    [self viewDidLoad];


    }




}


even after selecting index path 2 in section tableview section one my menu bar does not hide and the previous collection view data still exist in layout .




Aucun commentaire:

Enregistrer un commentaire