Chào cả nhà.
Em mới bắt đầu tìm hiểu về Objective C
đang làm một ứng dụng đơn giản về Delegate
em tạo một ứng dụng iOS đơn giản. có 2 ViewController: ViewController + NextViewController
Ở ViewController có chứa label + button1 (Click Me)
Ở NextViewController có cửa TextField + button2 (OK)

Khi bắt đầu chạy chương trình, thì ViewController 1 hiện lên, lúc này label = rỗng,

Em click button1 trên ViewController thì chuyển sang NextViewController
tại đây. ta có thể nhập String vào TextField
Sau khi nhập xong, click button2, thì ứng dụng trở về ViewController và Label sẽ nhận giá trị vừa nhập vào TextField ở NextViewController
Trên là ý định em làm một program đơn giản như vậy

Nhưng hiện tại, program của em vẫn chưa hoạt động chính xác.
Sau khi nhập giá trị vào TextField ở ViewController2, mà Label trên ViewController1 vẫn chưa nhận dc giá trị
Nhờ cả nhà xem em bị sai chỗ nào với ạ?
Click vào hình ảnh để lấy hình ảnh lớn

Tên:		hoi web.jpg
Lần xem:	0
Size:		97.3 KB
ID:		70989

NextViewController.h
Objective C Code:
  1. #import <UIKit/UIKit.h>
  2.  
  3. NS_ASSUME_NONNULL_BEGIN
  4. @protocol SendData
  5. -(void)showString:(NSString *)string;
  6. @end
  7.  
  8. @interface NextViewController : UIViewController
  9. @property (weak, nonatomic) IBOutlet UITextField *txtFullName;
  10. @property (weak, nonatomic) IBOutlet UIButton *btnOK;
  11. @property(weak,nonatomic)id<SendData>delegate;
  12. @end
  13.  
  14. NS_ASSUME_NONNULL_END

NextViewController.m
Objective C Code:
  1. #import "NextViewController.h"
  2.  
  3. @implementation NextViewController
  4.  
  5. - (void)viewDidLoad {
  6.     [super viewDidLoad];
  7. }
  8. - (IBAction)btnOKMethod:(id)sender {
  9.     [self.delegate showString:self.txtFullName.text];
  10.     [self dismissViewControllerAnimated:YES completion:nil];
  11. }
  12. @end

ViewController.h
Objective C Code:
  1. #import <UIKit/UIKit.h>
  2. #import "NextViewController.h"
  3.  
  4. @interface ViewController : UIViewController<SendData>
  5. @property (weak, nonatomic) IBOutlet UILabel *lblResult;
  6.  
  7. @end

ViewController.m
Objective C Code:
  1. #import "ViewController.h"
  2. #import "NextViewController.h"
  3.  
  4. @implementation ViewController
  5.  
  6. - (void)viewDidLoad {
  7.     [super viewDidLoad];
  8.     self.lblResult.text = @"";
  9.     NextViewController *nextViewController = [[NextViewController alloc]init];
  10.     nextViewController.delegate = self;
  11. }
  12.  
  13. - (IBAction)Click:(id)sender {
  14. }
  15.  
  16. - (void) showString:(NSString *)string{
  17.     self.lblResult.text = string;
  18. }
  19. @end

Mong nhận được chỉ hướng dẫn của mọi người ạ !