Всем привет, у меня такая проблема, не получается написать делегат. По задумке есть 2 вью контроллера, в одном из них есть UItextBox, в который юзер вводит число с плавающей точкой, и кнопка. Число должно передаваться в другой вью контроллер по нажатию кнопки и выводиться там в UIabel. Но этого не происходит. Я тут выложил свой код, подскажите, что я неправильно делаю? FirstViewController.h
Код | #import <UIKit/UIKit.h> #import "DelegateProtocol.h" @interface FirstViewController : UIViewController{ IBOutlet UITextField *textfield1, *textfield2; __unsafe_unretained id <DelegateProtocol> _delegate;
} @property (nonatomic, assign) id <DelegateProtocol> delegate; - (IBAction) ButtonClick:(id) sender; @end ;
|
FirstViewController.m
Код | #import "FirstViewController.h"
/*@interface FirstViewController ()
@end*/
@implementation FirstViewController @synthesize delegate=_delegate; - (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. } - (IBAction) ButtonClick:(id) sender{ float g = [textfield1.text floatValue]; [self.delegate SendA:g]; }
@end
|
Код | #import <UIKit/UIKit.h> #import "DelegateProtocol.h" #import "FirstViewController.h" @interface SecondViewController : UIViewController<DelegateProtocol> { float _a, _b; IBOutlet UILabel * Alabel, *Blabel; } @property float a, b; @end
|
SecondViewController.m
Код | #import "SecondViewController.h"
/*@interface SecondViewController ()
@end*/
@implementation SecondViewController @synthesize a=_a; - (void)viewDidLoad { [super viewDidLoad]; FirstViewController * testAppViewController = [[FirstViewController alloc] init]; testAppViewController.delegate = self; // Do any additional setup after loading the view, typically from a nib. } -(void) SendA:(float) A{ self.a = A ; NSString *str = [NSString stringWithFormat:@"%f", self.a]; [Alabel setText:str]; }
- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
@end
|
|