文字列変数を mainVC クラスから detailVC クラスに渡そうとしていますが、viewDidLoad が起動されると、myStringLabel が空になり、「Just a test」が含まれているはずです。どうしてか分かりません。
mainVC.m
#import "mainVC.h"
@implementation mainVC
@synthesize
-(IBAction) openSecondController {
//Ouverture de DetailVC
detailVC *dVC = [[detailVC alloc] init];
dVC.myStringLabel=@"Just a test";
NSLog(@"dVC.myStringLabel before calling dVC :%@", dVC.myStringLabel);
[self performSegueWithIdentifier:@"progDetailSegue" sender:nil];
NSLog(@"dVC.myStringLabel after calling dVC :%@", dVC.myStringLabel) ;
}
詳細VC.h
#import <UIKit/UIKit.h>
@interface detailVC : UIViewController {
NSString *myStringLabel;
IBOutlet UILabel *labelForString;
}
@property (nonatomic, strong) UILabel *labelForString;
@property (copy) NSString *myStringLabel;
詳細VC.m
#import "detailVC.h"
@implementation detailVC
@synthesize myStringLabel, labelForString;
-(void) viewDidLoad {
NSLog(@"myStringLabel in viewDidLoad : %@", dVC.myStringLabel) ;
labelForString.text=myStringLabel;
}
-(IBAction) closeViewController {
//Fermeture com_mobilizProgramDetailViewController ouverte en Modal.
[self dismissViewControllerAnimated:YES completion:nil];
}
NSLOG 出力:
2012-12-17 11:48:58.520 DataTransfert[5068:f803] dVC.myStringLabel before calling dVC : Just a test
2012-12-17 11:48:58.520 DataTransfert[5068:f803] myStringLabel in viewDidLoad : (null)
2012-12-17 11:48:58.520 DataTransfert[5068:f803] dVC.myStringLabel after calling dVC :Just a test