title: Set Text of an UILabel after dismissViewController in other Class
body: <p>I haven't found a similar question that could answer my question.</p>
  <p>My Question is: Why can't I access a UILabel from another class after the dissmissViewController?</p>
  <p>Here is my Code:</p>
  <p>ClassA.h:</p>
  <pre><code>@interface ClassA : UIViewController {
      UILabel *_ErrorLabel;
      UIActivityIndicatorView *_acIn1;
  }
  
  @property (weak, nonatomic) IBOutlet UILabel *ErrorLabel;
  @property (weak, nonatomic) IBOutlet UIActivityIndicatorView *acIn1;
  </code></pre>
  <p>ClassA.m:</p>
  <pre><code>shouldPerformSegue, prepareForSegue and statusBarStyle Methods
  </code></pre>
  <p>ClassB.h:</p>
  <pre><code>- (IBAction)dismiss;
  </code></pre>
  <p>ClassB.m:</p>
  <pre><code>- (IBAction)dismiss
  {
    [self dismissViewControllerAnimated:YES completion:^{
        ClassA *login = [[ClassA alloc] init];
        [[login ErrorLabel] setText:@&quot;Please use login.&quot;];
        [[login acIn1] stopAnimating];
        [[login acIn1] setHidesWhenStopped:YES];
        [[login acIn1] setHidden:YES];
    }];
  }
  </code></pre>
  <p>Here is my Code I really hope somebody can help me: I AM ABOUT TO GIVE UP I DON'T KNOW WHY THIS WON'T WORK!</p>
  <p>Thanks for your help.</p>
  <p>~Markus</p>
  <p>Edit1:</p>
  <p>I have a ViewController ClassA that contains two text fields and when you click on login you come to a TabBarController where one tab contains the ClassB ViewController and in the ClassB ViewController there is a logout button --&gt; dismiss and when you click this button you should come to the ClassA ViewController AND the ErrorLabel Text should change.</p>
  <p>Complete Class: A --&gt; LoginViewControler.h</p>
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import &quot;ShowProfileViewController.h&quot;
  
  @interface LoginViewController : UIViewController &lt;ShowProfileViewControllerDelegate&gt; {
      UILabel *_ErrorLabel;
      UIActivityIndicatorView *_acIn1;
  }
  
  @property (weak, nonatomic) IBOutlet UITextField *usernameTextField;
  @property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
  @property (weak, nonatomic) IBOutlet UILabel *ErrorLabel;
  @property (weak, nonatomic) IBOutlet UIActivityIndicatorView *acIn1;
  
  @end
  </code></pre>
  <p>Complete Class: A --&gt; LoginViewController.m</p>
  <pre><code>#import &quot;LoginViewController.h&quot;
  #import &quot;NewsNavigationController.h&quot;
  #import &quot;TabViewController.h&quot;
  
  @interface LoginViewController () &lt;UITextFieldDelegate&gt;
  
  @end
  
  @implementation LoginViewController
  
  @synthesize usernameTextField;
  @synthesize passwordTextField;
  @synthesize ErrorLabel;
  @synthesize acIn1;
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
      [usernameTextField setDelegate:self];
      [passwordTextField setDelegate:self];
  }
  
  - (void)didReceiveMemoryWarning
  {
      [super didReceiveMemoryWarning];
  }
  
  - (UIStatusBarStyle)preferredStatusBarStyle
  {
      return UIStatusBarStyleLightContent;
  }
  
  - (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
  {
      
      if([identifier isEqualToString:@&quot;login&quot;])
      {
          [acIn1 startAnimating];
          [acIn1 setHidden:NO];
          if([self login]){
              return YES;
          } else {
              [self showErrorMessage:@&quot;Data not correct!&quot;];
              [acIn1 stopAnimating];
              [acIn1 setHidesWhenStopped:YES];
              [acIn1 setHidden:YES];
              return NO;
          }
      }
      else {
          [acIn1 stopAnimating];
          [acIn1 setHidesWhenStopped:YES];
          [acIn1 setHidden:YES];
          return NO;
      }
  }
  
  - (void)showErrorMessage:(NSString *)message
  {
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@&quot;Error!&quot;
                                                      message:message
                                                      delegate:self
                                                      cancelButtonTitle:@&quot;OK&quot;
                                                      otherButtonTitles:nil];
      [alert show];
  }
  
  - (BOOL)login
  {
      NSString *usernameS = usernameTextField.text;
      NSString *passwordS = passwordTextField.text;
      
      NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@&quot;http://localhost:8888/login.php?username=%@&amp;password=%@&quot;, usernameS, passwordS]]];
      
      NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
  
      NSDictionary *loginDic = [jsonDictionary objectForKey:@&quot;login&quot;];
  
      NSString *ErrorString = [loginDic objectForKey:@&quot;returnString&quot;];
      
      NSLog(@&quot;[+] Login: %@&quot;, ErrorString);
      
      if ([ErrorString isEqualToString:@&quot;Success&quot;]){
          ErrorLabel.text = @&quot;Login&quot;;
          return YES;
      }
      else {
          ErrorLabel.text = ErrorString;
          return NO;
      }
      
  }
  
  - (void)didDismissViewController
  {
      [ErrorLabel setText:@&quot;Bitte benutzen Sie den Login.&quot;];
      [acIn1 stopAnimating];
      [acIn1 setHidesWhenStopped:YES];
      [acIn1 setHidden:YES];
  }
  
  - (void)prepareForSegue:(UIStoryboardSegue *)inSegue sender:(id)inSender
  {
      if([inSegue.identifier isEqualToString:@&quot;login&quot;])
      {
          ShowProfileViewController *vc = [[ShowProfileViewController alloc] init];
          vc.delegate = self;
          TabViewController *tabViewController = inSegue.destinationViewController;
          NewsNavigationController *theController = [[tabViewController viewControllers] objectAtIndex:0];
          [self presentViewController:vc animated:YES completion:nil];
      }
  }
  
  
  @end
  </code></pre>
  <p>Complete Class: B --&gt; ShowProfileViewController.h</p>
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @protocol ShowProfileViewControllerDelegate
  
  - (void)didDismissViewController;
  
  @end
  
  @interface ShowProfileViewController : UIViewController
  
  @property (nonatomic, assign) id&lt;ShowProfileViewControllerDelegate&gt; delegate;
  
  - (IBAction)dismiss;
  
  @end
  </code></pre>
  <p>Complete Class: B --&gt; ShowProfileViewController.m</p>
  <pre><code>#import &quot;ShowProfileViewController.h&quot;
  #import &quot;LoginViewController.h&quot;
  
  @interface ShowProfileViewController ()
  
  @end
  
  @implementation ShowProfileViewController
  
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
  }
  
  - (void)didReceiveMemoryWarning
  {
      [super didReceiveMemoryWarning];
  }
  
  -(BOOL) textFieldShouldReturn:(UITextField *)textField{
      
      [textField resignFirstResponder];
      return YES;
  }
  
  - (void)viewWillAppear:(BOOL)inAnimated
  {
      [super viewWillAppear:inAnimated];
  }
  
  - (IBAction)dismiss
  {
      [self dismissViewControllerAnimated:YES completion:^{
          [self.delegate didDismissViewController];
      }];
  }
  
  @end
  </code></pre>