2012-03-21 71 views
0

在ViewController 1中我調用ViewController 2中的函數「changeButtonMessage」,它應該更改UILabel的文本。該函數被調用(NSLog工作),但標籤沒有被改變。謝謝你的幫助。在另一個視圖控制器中調用函數

視圖控制器1

loadingViewController *controller; 
controller = [[loadingViewController alloc] init]; 
NSString *mymsg = [NSString stringWithFormat: @"Loading"]; 
[controller changeButtonMessage:mymsg]; 
@property (nonatomic, retain) IBOutlet UILabel *loadingtxt; 
- (IBAction)changeButtonMessage:(id)sender; 

@synthesize loadingtxt; 

-(void)changeButtonMessage: (NSString*) newMessage { 

    loadingtxt.text = newMessage; 
    NSLog(@"Change label to %@",newMessage); 

} 

回答

0

如果UIViewController.view財產尚未訪問,您所創建的對象的ViewController(ALLOC,INIT),但觀點實際上ISN沒有加載,它的子視圖尚未加載。

loadingtxt可能爲零。你可以通過調試或NSLog來驗證它。

到的loadView或viewDidLoad中一直呼籲的UIViewController

如何創建您的視圖控制器這不會是有效的? StoryBoard? Nib文件?

+0

感謝您的回覆。視圖控制器在ViewController1的ViewDidLoad中被創建爲ModalViewController'loadingViewController * loadingView = [[[loadingViewController alloc] init] autorelease]; loadingView.modalPresentationStyle = UIModalPresentationFormSheet; [self presentModalViewController:loadingView animated:NO];' – user1104325 2012-03-21 16:37:20

+0

如何在視圖控制器中創建視圖?也許你需要使用initWithNibName初始化方法,如果你有一個關聯的nib文件...你是否再次調試過,並檢查加載txt是否爲零? – bandejapaisa 2012-03-21 16:48:39

相關問題