Alexey
Alexey

Reputation: 7257

how to set the property of the ViewController before presenting it as presentModalViewController?

I present the view controller like this:

FBViewController *fbViewController =[[FBViewController alloc] initWithNibName:@"FBViewController" bundle:nil];
fbViewController.label.text=@"hello"; // I set the value of the property label which is the outlet
[self presentModalViewController:fbViewController animated:YES];

FBViewController.h:

#import <UIKit/UIKit.h>

@interface FBViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *label;

@end

FBViewController.m:

...
- (void)viewDidLoad
{
    [super viewDidLoad];

    NSLog(@"%@", self.label.text); // Here instead of "hello" i get the value which was in nib file.

}
...

The question is how to set the value of the label?

Upvotes: 0

Views: 2527

Answers (1)

Dinesh
Dinesh

Reputation: 6532

You can pass the NSString retrieve text to assign label modalview controller:

FBViewController *fbViewController =[[FBViewController alloc]   initWithNibName:@"FBViewController" bundle:nil];
 fbViewController.labeltext=@"Your Text";
 [self presentModalViewController:fbViewController animated:YES];

FBViewController.h

@interface FBViewController : UIViewController {

 NSString *labeltext;

}

@property (nonatomic, retain) NSString *labeltext;

and use view to load method in FBViewController.m

- (void)viewDidLoad {
  label1.text=labeltext;
}

Upvotes: 1

Related Questions