Pregunta

hii i am making an app in which i have to give the login page on one tab bar controller but this login page opens only when user not logged in but when user already logged in then this tab bar controller opens after login page.
I write code for this and it works fine but when user again click on the tab bar controller then it opens the login page again either user is already logged in.So how to prevent this means how can i open after login page when user is logged in.

My code is:

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

         }
¿Fue útil?

Solución

You can use this in alternate idea k, use to store the login crentIal in local mean (use NSUserDefault ) , cal this NSUserdefault in AppDelegate.m , this method is used for directly call the particular view controller otherwise you pass the seque in login view controller.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top