0
我是Xcode與故事板編程的新手。 我想從「SecondViewController」傳遞一個值(標籤文本)到「視圖控制器」。 這裏是我的代碼:在兩個視圖之間傳遞值 - Xcode 4.2與故事板
ViewController.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
SecondViewController.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;
}
有人可以幫助我嗎? 非常感謝!
斯特凡諾
謝謝Schnarchii!我解決了我的問題! – 2012-05-01 10:10:51
沒問題:)如果它幫助不接受答案不適合我,但其他。所以如果他們有類似的問題,他們可以選擇最好的解決方案。它幫助你和stackoverflow .. – Quirin 2012-05-01 10:30:16