2014-12-03 66 views
0

我正在开发一个iOS应用程序,其中使用了自定义集合视图。在菜单栏中它有3个控制器1,2,3的列表。当我选择2时,我想创建一个新的集合视图布局并清除前一个。是否可以清除以前的集合视图布局中的数据?集合视图正在以编程方式创建iOS。如何清除集合视图布局上的内容ios

这是我的一段代码。

- (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]; 
    } 


} 

即使部分实现代码如下节一个我的菜单栏没有隐藏和以前的集合视图数据选择索引路径2后在布局仍然存在。

+0

为什么不重新装入乌尔新的数据相同的集合视图 – 2014-12-03 07:52:41

+0

u能告诉我如何shud我重装了新的数据 – user3659166 2014-12-03 08:50:29

回答

2
- (void)viewWillAppear:(BOOL)animated 
{ 


    [self.yourcollectionView reloadData]; 

    [super viewWillAppear:animated]; 
} 
0

你应该叫:

[collectionView.collectionViewLayout invalidate]; 
+0

我想你的方法集合视图。但仍然有同样的问题。 – user3659166 2014-12-03 08:49:57

+0

YoursLayout * layout = [[YoursLayout alloc] init]; – mityaika07 2014-12-03 08:55:51

+0

[self.collectionView setCollectionViewLayout:layout]; – mityaika07 2014-12-03 08:56:09