Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing NSArray makes array empty
    primarykey
    data
    text
    <p>i'm trying to pass an array from a view to another using the PrepareForSegue method. In the first view i got a button called "Submit" that, if pressed, reads a textView and store the text in a NSArray, and then should pass this array to another view (push segue), but when the array arrives is empty. Here is the code</p> <pre><code>//.h @property (strong, nonatomic) NSArray *words; //.m - (IBAction)Submit:(id)sender{ //read textView _words = [self.myTextView.text componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { //if Submit is pressed go to SecondViewController if ([segue.identifier isEqualToString:@"secondSegue"]) { SecondViewController *vc = [segue destinationViewController]; vc.array = _words; } } </code></pre> <p>So here is the code of the SecondViewController that receives the array</p> <pre><code>- (void)viewDidLoad { [self Calculate]; [super viewDidLoad]; // Do any additional setup after loading the view. } -(void)Calculate { int size = [array count]; NSLog(@"size is %d",size); } </code></pre> <p>the log always says "size is 0". Did i make some mistake? Could it be that the Segue happens before i can read the TextView and fill the array so it's always empty? thanks in advance!</p> <p><strong>EDIT:</strong> I tried to NSLog the Submit action and i discovered that the program never accesses to it, so it never reads! (p.s. yes i connected the button) So the segue happens before the Submit action How can i solve? can i copy the PrepareForSegue code in the Submit action?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload