0
我有两个视图控制器...传递数据TextView使用协议
ViewController 1有一个标签,应该显示通过TextView输入的文本。
的视图控制器2具有通过文本的视图控制器1
标签要做到这一点我使用的协议这样一个TextView
头文件VC2.h
@protocol TransferTextViewDelegate <NSObject>
-(void)PassedData:(NSString *)text;
@end
@interface VC2 : UIViewController <UITextViewDelegate>
@property (nonatomic, weak)id <TransferTextViewDelegate> delegate;
@property (strong, nonatomic) IBOutlet UITextView *FFTextView;
@property (strong, nonatomic) NSString *title;
- (IBAction)sendTextViewcontent:(id)sender;
@end
在执行文件VC2.m
#import "VC2.h"
#import "VC1.h"
@interface VC2()
@end
@implementation VC2
@synthesize FFTextView;
@synthesize delegate;
@synthesize title;
- (void)viewDidLoad {
[super viewDidLoad];
[FFTextView becomeFirstResponder];
FFTextView.delegate = self;
}
- (IBAction)sendTextViewcontent:(id)sender {
if (delegate) {
title = FFTextView.text;
[delegate PassedData:title];
}
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
在视图控制器1,就像我说的,这是一个UILabel应该显示在视图控制器2
实现文件VC1.m
-(void)viewWillAppear:(BOOL)animated {
TitoloAnnuncio.text = TitoloAnnuncioInserito;
}
-(void)PassedData:(NSString *)text {
TitoloAnnuncioInserito = text;
}
的TextView的在输入的文本头文件VC1.h实现这个属性:
@property (strong, nonatomic) IBOutlet UILabel *TitoloAnnuncio;
@property (strong, nonatomic) NSString *TitoloAnnuncioInserito;
我的问题是,我不明白为什么我的标签不显示文本..它仍然是空的...我不能从1 ViewController中的ViewController 2传递数据 你能帮忙吗?