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);
}
感謝您的回覆。視圖控制器在ViewController1的ViewDidLoad中被創建爲ModalViewController'loadingViewController * loadingView = [[[loadingViewController alloc] init] autorelease]; loadingView.modalPresentationStyle = UIModalPresentationFormSheet; [self presentModalViewController:loadingView animated:NO];' – user1104325 2012-03-21 16:37:20
如何在視圖控制器中創建視圖?也許你需要使用initWithNibName初始化方法,如果你有一個關聯的nib文件...你是否再次調試過,並檢查加載txt是否爲零? – bandejapaisa 2012-03-21 16:48:39