【问题标题】:how to open same page when i click on same tab bar controller当我点击同一个标签栏控制器时如何打开同一个页面
【发布时间】:2014-04-19 12:24:32
【问题描述】:

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

我的代码是:

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

         }

【问题讨论】:

    标签: ios uitabbarcontroller


    【解决方案1】:

    您可以在替代想法 k 中使用此方法,用于以本地平均值存储登录凭据(使用 NSUserDefault ),在 AppDelegate.m 中调用此 NSUserdefault ,此方法用于直接调用特定视图控制器,否则您传递序列在登录视图控制器中。

    【讨论】:

      猜你喜欢
      • 2020-01-10
      • 1970-01-01
      • 2019-04-30
      • 2016-12-19
      • 1970-01-01
      • 2016-02-26
      • 1970-01-01
      • 2016-02-19
      • 2017-12-23
      相关资源
      最近更新 更多