Please help, I suffer the whole day. Suppose I have 2 ViewController (ViewController and TwoViewController). On the first view I have a button to go to the TwoViewController and UISegmentedControl. I want the array NSMutableArray under the index 0 to record the readings of this controller segment. Then transfer this array to TwoViewController and, at the click of a button on TwoViewController, change the text of lable, which is also on the same view. The Internet is full of examples, but for some reason the array comes to me empty. My code when trying to issue this through delegates
//ViewController.h #import <UIKit/UIKit.h> @protocol ProtocolPrint; @interface ViewController : UIViewController - (IBAction)go:(UIButton *)sender; - (IBAction)segment:(UISegmentedControl *)sender; @property(strong, nonatomic) NSMutableArray* info; @property(weak, nonatomic) id <ProtocolPrint> delegate; @end @protocol ProtocolPrint -(NSString*) print:(ViewController*) inf; @end // ViewController.m #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.info = [NSMutableArray arrayWithObjects:@"", nil]; } //кнопка перехода к TwoViewController - (IBAction)go:(UIButton *)sender { UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; ViewController *test = [storyBoard instantiateViewControllerWithIdentifier:@"Storyboard2"]; [self presentViewController:test animated:YES completion:nil]; } - (IBAction)segment:(UISegmentedControl *)sender { switch (sender.selectedSegmentIndex) { case 0: self.info[0] = @"значение 1"; break; case 1: self.info[0] = @"значение 2"; break; case 2: self.info[0] = @"значение 3"; break; case 3: self.info[0] = @"значение 4"; break; default: break; } } @end // TwoViewController.h #import <UIKit/UIKit.h> #import "ViewController.h" @interface TwoViewController : UIViewController <ProtocolPrint> - (IBAction)back:(UIButton *)sender; - (IBAction)editText:(UIButton *)sender; @end // TwoViewController.m #import "TwoViewController.h" @interface TwoViewController () @property (weak, nonatomic) IBOutlet UILabel *label; @property (weak, nonatomic) ViewController *oneVC; @end @implementation TwoViewController - (void)viewDidLoad { [super viewDidLoad]; _oneVC.delegate = self; } - (IBAction)back:(UIButton *)sender { [self dismissViewControllerAnimated:YES completion:nil]; } - (IBAction)editText:(UIButton *)sender { self.label.text = [self print:self.oneVC]; } - (NSString *)print:(ViewController *)inf { return inf.info[0]; } @end I tried to solve this issue through a singleton, through an example here.
How to transfer a variable from one class to another?
and here
but the result is the same; nothing appears on the label on the label, the element of the array [0] remains @ "". Tell a newbie in iOS, what's the problem ??