当我点击相同的标签栏控制器时如何打开同一页面

时间:2014-04-19 12:24:33

标签: ios uitabbarcontroller

我正在创建一个应用程序,我必须在一个标签栏控制器上提供登录页面,但只有当用户未登录但用户已登录时才会打开此登录页面,然后在登录页面后打开此标签栏控制器。
我为此编写代码并且工作正常但是当用户再次单击选项卡栏控制器时,它再次打开登录页面,用户已经登录。所以如何防止这意味着如何在用户登录后在登录页面后打开英寸

我的代码是:

 (void)viewDidLoad
      {
         [super viewDidLoad];
         UIImage *image1 = [UIImage imageNamed: @"logo.png"];
         UIImageView *imageView1 = [[UIImageView alloc] initWithImage: image1];
        self.navigationItem.titleView = imageView1;
         self.navigationItem.leftBarButtonItem = nil;
         self.navigationItem.hidesBackButton = YES;

          @try
           {
            NSUserDefaults *def5=[NSUserDefaults standardUserDefaults];
           NSLog(@"%@",[def5 objectForKey:@"id"]);
           if ([[def5 objectForKey:@"id"]isEqualToString:NULL])
             {
             storeinformation=[[NSMutableArray alloc]init];
              dict=[[NSMutableDictionary alloc]init];
             [dict setValue:@"Mine Annonser" forKey:@"name"];
               [dict setValue:@"2" forKey:@"id"];
             [storeinformation addObject:dict];

              dict=[[NSMutableDictionary alloc]init];
              [dict setValue:@"Sett inn annonse" forKey:@"name"];
              [dict setValue:@"3" forKey:@"id"];
               [storeinformation addObject:dict];
             }
             else
              {
                 UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
                Logindisplay *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"log"];
                [self.navigationController pushViewController:vc animated:YES];

               }


        }

        @catch (NSException *exception)
        {
              NSLog(@"error in loading in vc%@", exception.reason);
         }

          image1=Nil;
          imageView1=nil;

        }




          - (void)didReceiveMemoryWarning
             {
               [super didReceiveMemoryWarning];
             // Dispose of any resources that can be recreated.
             }  



           - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
            {

              return 1;
             }

        - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
           {

              return [storeinformation count];
             }

           - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
             {
                 @try
                    {
                       NSUserDefaults *def6=[NSUserDefaults standardUserDefaults];
                         if ([[def6 objectForKey:@"id"]isEqualToString:NULL])
                            {
                              static NSString *CellIdentifier=@"afterlogin";
                               UITableViewCell *cell=[tableView  dequeueReusableCellWithIdentifier:CellIdentifier];

                 if (cell==nil)
                     {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
                     }


                 // arr=[storeinformation objectAtIndex:indexPath.row];
                   //NSLog(@"%@",arr);
                    NSMutableDictionary *dict1=[storeinformation objectAtIndex:indexPath.row];
                UILabel *lbl=(UILabel*)[cell viewWithTag:1];
                lbl.text= [dict1 objectForKey:@"name"];
                UIImageView *img2=(UIImageView*)[cell viewWithTag:100];
                img2.image=[UIImage imageNamed:@"arrows.png"];
             / /  NSLog(@"%@",[storeinformation objectAtIndex:0]);
                   return cell;
               //dict1=Nil;
                // lbl=Nil;
            }
            }

            @catch (NSException *e)
                {
                    NSLog(@"Error in row at index path%@",e.reason);
                 }

         }

1 个答案:

答案 0 :(得分:0)

你可以在备用的想法k中使用它,用于存储本地平均值的登录crentIal(使用NSUserDefault),在AppDelegate.m中调用此NSUserdefault,此方法用于直接调用特定的视图控制器,否则你通过seque在登录视图控制器中。