我是使用故事板进行 Xcode 编程的新手。我正在尝试将一个值(标签的文本)从“SecondViewController”传递给“View Controller”。这是我的代码:
视图控制器.m
- (IBAction)showSecondView:(id)sender {
NSLog(@"Trying..");
// The identifier used here is set on the second view controller in the UIStoryboard.
SecondViewController *svc = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondIdentifier"];
NSLog(@"Test: %@",svc.labelTest.text); //this print NIL!!
svc.labelTest.text = @"GOOFY!!";
[self.navigationController pushViewController:svc animated:YES];
}
SecondViewController.h
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController
- (IBAction)returnToFirstView:(id)sender;
- (IBAction)toTabBar:(id)sender;
@property (strong, nonatomic) IBOutlet UILabel *labelTest;
@end
第二视图控制器.m
#import "SecondViewController.h"
@implementation SecondViewController
@synthesize labelTest;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
有人可以帮助我吗?非常感谢!
斯特凡诺