Pergunta

I'm sorry for my english.

My question is how to pass a data from a login viewcontroller to frontviewcontroller of the SWRevealViewController library. Let me explain my situation.

My app has a login view. If the login informations are ok you can enter inside the app where the menu would be managed by SWRevealViewController.

This is my storyboard:

mystoryboard app

To "remember" who is the user that was logged-in i want to pass an ID from the loginview (in my storyboard called "View Controller") to "HomeappViewController".

In my ViewController prepareforsegue method i wrote this code:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
  if ([[segue identifier] isEqualToString:@"entrataApp"]) {
    SWRevealViewController *destination = [segue destinationViewController];
    UINavigationController *navViewController = (UINavigationController *) [destination frontViewController];
    HomeAppViewController *destViewController = (HomeAppViewController* )[navViewController topViewController];
    destViewController.testoPassato = risposta;
  }
}

And in HomeAppViewControllerthis is my viewDidLoad:

- (void)viewDidLoad{
   [super viewDidLoad];
   // Do any additional setup after loading the view.
   self.title = @"News";

   // Set the side bar button action. When it's tapped, it'll show up the sidebar.
   _sidebarButton.target = self.revealViewController;
   _sidebarButton.action = @selector(revealToggle:);

   // Set the gesture
   [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];

   _datiPassati.text = _testoPassato;
}

As you can see i try to pass "risposta" that contain my "user ID" to destViewController.testoPassato that is the label inside HomeAppViewController but when i launch the code the label staies empty.

In your opinion which is my error? Maybe do i need to define homeAppViewController as frontviewcontroller? How can i do that?

I'm sorry if my question is stupid but i'm new in iOS app development.

Foi útil?

Solução

i think you will need to know who is logged in user through out the application what you can do is to store the user id when user log in from the response of the webservice

you can store that using following

[[NSUserDefaults standardUserDefaults] setValue:[dictData valueForKey:@"id"] forKey:@"uid"];

here dictData is my response dictionary and field is id

Further add these to your constant or in your .pch file

#define UserId     [[NSUserDefaults standardUserDefaults] valueForKey:@"uid"]

and then use UserId where ever you need in the application in any viewController in any class.

When you want to provide the Logout Facility in the application give

NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];

These will remove all the keys and again when you execute the application it will go the login page.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top