我正在使用多個視圖控制器並嘗試將一個視圖控制器中的UITextfield鏈接到使用委託的另一個視圖控制器中的標籤。在多個視圖控制器中使用代理
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITextFieldDelegate>
{
IBOutlet UITextField *txtField;
}
@end
ViewController.m
#import "ViewController.h"
#import "ViewController2nd.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
lbl.text = [NSString stringWithFormat:@"Hello, %@",txtField.text]
[txtField resignFirstResponder];
return YES;
}
@end
ViewController2nd.h
#import <UIKit/UIKit.h>
@interface ViewController2nd : UIViewController <UITextFieldDelegate> {
IBOutlet UILabel *lbl;
}
@end
ViewController2nd.m
#import "ViewController2nd.h"
@interface ViewController2nd()
@end
@implementation ViewController2nd
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
我得到的錯誤是:
在Viewcontroller.m
不知道如何解決這個問題,使用未聲明的標識符LBL的。需要一些指導..謝謝...
所以如果你想比你要做到這一點與ViewController2nd的'對象使用它在'ViewController'我想你已經宣佈''lbl'in ViewController2nd' '。 – Krunal