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傳遞數據 你能幫忙嗎?