0

我呈現視圖控制器是這樣的:如何在呈現爲presentModalViewController之前設置ViewController的屬性?

FBViewController *fbViewController =[[FBViewController alloc] initWithNibName:@"FBViewController" bundle:nil]; 
[email protected]"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. 

} 
... 

的問題是如何設置標籤的值?

回答

1

您可以通過檢索NSString的文本分配標籤modalview控制器:

FBViewController *fbViewController =[[FBViewController alloc] initWithNibName:@"FBViewController" bundle:nil]; 
[email protected]"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; 
} 
+0

加載方法謝謝你的答案。你知道我的代碼爲什麼不起作用嗎?爲什麼我不能直接設置插座的屬性? – Alex 2012-03-26 08:21:09

+0

因爲控件在模態視圖控制器上重新生成顯示和標籤文本集默認文本....! – Dinesh 2012-03-26 09:21:15

相關問題