0

我这样呈现视图控制器:

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.

}
...

问题是如何设置标签的值?

4

1 回答 1

1

您可以通过 NSString 检索文本来分配标签 modalview 控制器:

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;

并使用视图在 FBViewController.m 中加载方法

- (void)viewDidLoad {
  label1.text=labeltext;
}
于 2012-03-26T08:08:47.700 回答