Looked all the themes about accessing NSMuatableArray from different class and tried all the answers but still can't access that MutableArray from different class.
My code:
ViewController.m
@interface ViewController () <UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) NSArray *printProductImages;
@property (strong, nonatomic) NSArray *printProductNames;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.delegate = self;
self.tableView.dataSource = self;
_printProductImages = [NSArray arrayWithObjects:@"demo_1.jpg", @"demo_2.jpg", @"demo_3.jpg",nil];
_printProductNames = [NSArray arrayWithObjects:@"text", @"text", nil];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
AnotherViewController *anotherVC = [[AnotherViewController alloc] init];
switch (indexPath.row) {
case 0:
[anotherVC.array1 removeAllObjects]; // does not work and no error
[anotherVC.array1 addObjectsFromArray:_printProductImages]; // does not work and no error
[anotherVC.array2 removeAllObjects]; // does not work and no error
[anotherVC.array2 addObjectsFromArray:_printProductNames]; // does not work and no error
[self performSegueWithIdentifier:@"AnotherViewController" sender:self];
NSLog(@"~~Row: 1");
break;
case 1:
NSLog(@"~~Row: 2");
break;
default:
break;
}
AnotherViewController.h
@interface AnotherViewController: UIViewController
@property (strong, nonatomic) NSMutableArray *array1;
@property (strong, nonatomic) NSMutableArray *array2;
@end
AnotherViewController.m
@implementation AnotherViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.delegate = self;
self.tableView.dataSource = self;
_array1 = [NSMutableArray arrayWithObjects:@"demo_3.jpg", @"demo_4", @"demo_1.jpg", @"demo_2.jpg",nil]; // I want to delete these objects and load new objects to this array
_array2 = [NSMutableArray arrayWithObjects:@"BIG", @"SMALL", @"MEDIUM", @"SUPER GOOD", nil]; // I want to delete these objects and load new objects to this array