好吧,这是我昨晚问的问题的延伸.我对如何使用各种技术在视图控制器之间传递数据有一点了解.我想进入MVC路线,创建一个Singleton类似乎是最接近MVC的概念.
基本上我用两个View Controllers和一个singleton类创建了一个简单的应用程序.我试图将文本字段的值传递给UILabel.无论出于何种原因它都无法正常工作 这就是我的代码.
ViewController.h
#import <UIKit/UIKit.h>
#import "Model.h"
#import "ViewController2.h"
@interface ViewController : UIViewController {
NSString *text2pass;
}
@property (weak, nonatomic) IBOutlet UITextField *tf;
@property (weak, nonatomic) IBOutlet UILabel *btn;
- (IBAction)go:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize tf = _tf;
@synthesize btn = _btn;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *tfstring = _tf.text;
NSLog(@"string = %@",tfstring);
}
- (void)viewDidUnload
{ …Run Code Online (Sandbox Code Playgroud)