I firstly apologize for the question title which probably doesn't make much sense or is super obvious. I have a tabbarcontroller
with two views on it (view1
and view2
). It starts off at view1
as initial view. I need to pass something from view1
to view2
which I have figured out thanks to this awesome community =]. However when I run the simulator, as I start off on view1
if i pass the object then and there, nothing happens but if I go to "see" view2
first and then move back to view1
, the object is received perfectly. I think this is an issue of view2
's array2
not existing at first until I actually ask to see it since it is initialized in viewDidLoad. Any help is appreciated. Thanks.
this is my viewDidLoad in view2:
[super viewDidLoad];
// Do any additional setup after loading the view.
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
self.array2 =[[NSMutableArray alloc]init];
this is the method of a button push in view1 that gives the object to view2:
object = [self.array1 objectAtIndex:15];
UINavigationController *navi = (UINavigationController *)[[self.tabBarController viewControllers] objectAtIndex:1];
SecondViewController *secViewController = [[navi viewControllers] objectAtIndex:0];
[secViewController.array2 addObject:object];
[secViewController.tableView reloadData];
I "think the problem is that I should init the array2
earlier than viewDidLoad
and Im guessing this would be in the init of the viewController. I do not know how to do this, my VC2.m does not have an init method and Im not sure as how to make it init the array2
before I go to this screen.