Note that there are some explanatory texts on larger screens.

plurals
  1. POObject of array in new ViewController keeps empty
    text
    copied!<p>I've a problem with an array. There's an array with some objects of the class Car in my CarViewController:</p> <p>...Car.h</p> <pre><code>@interface Car : NSObject @property (nonatomic, strong) NSString *name; </code></pre> <p>..and Car.m</p> <pre><code>- (void)encodeWithCoder:(NSCoder *)coder; { [coder encodeObject:name forKey:@"name"]; } - (id)initWithCoder:(NSCoder *)coder; { self = [[Car alloc] init]; if (self != nil) { name = [coder decodeObjectForKey:@"name"]; } return self; } </code></pre> <p>and CarViewController</p> <pre><code> Car *car1 = [Car new]; car1.name = @"A1"; ... cars = [NSArray arrayWithObjects: car1, car2, ..., nil]; </code></pre> <p>But when I now try to have access to this array in NewViewController there is a problem:</p> <pre><code>- (IBAction)btn:(id)sender { UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil]; CarViewController *vc = (CarViewController *)[storyboard instantiateViewControllerWithIdentifier:@"CarVC"]; Car *car = [vc.cars objectAtIndex:0]; NSLog(@"%@", car.name); } </code></pre> <p>But in the log is just written that <strong>car.name = (null)</strong>. Thanks in advance to your effort.</p> <p><strong>UPDATE</strong>:</p> <pre><code>- (IBAction)btn:(id)sender { UINavigationController *nav = self.tabBarController.viewControllers[1]; CarViewController *vc = nav.topViewController; Car *car = [vc.cars objectAtIndex:0]; NSLog(@"%@", car.name); } </code></pre> <p>I've tried something (thanks to <strong>rdelmar</strong> for his effort), but the result is still the same.</p>
 

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