Reputation: 1034
I am having problem working with a SlidingViewController. My sliding view controller has a left view controller, a main view controller and a right view controller. My left view controller is a menu style view controller and switches the main view controller to a view controller selected. The right view controller is a table view controller that has recent searches using NSUserDefault keys. This key is an array that contains 4 strings. The problem I am having is sending this string back to the main view controller because the main view controller's viewWillAppear does not get called because technically it is never off the screen (ie it never disappears).
I've tried to make the view controller call the viewDidAppear manually but it seems as initializing the main view controller creates a whole new viewController all together and doesn't create the tableView inside the main view controller, therefore doesn't load reload a table view. Also, the tableView comes out as (null) when I log it.
Here is the didSelectRowAtIndexPath of LeftViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIStoryboard *iPhoneStoryBoard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
ViewController *viewController = (ViewController *)[iPhoneStoryBoard instantiateViewControllerWithIdentifier:@"HomePage"];
viewController.reloadArray = self.recentSearchesArray[indexPath.row];
NSLog(@"Recent ReloadArray: %@", viewController.reloadArray); //This prints out the correct information
/*
MenuViewController *menuViewController = [[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil];
SlidingViewController *slidingViewController = [[SlidingViewController alloc] initWithNibName:@"SlidingViewController" bundle:[NSBundle mainBundle] mainViewController:viewController leftViewController:menuViewController andRightViewController:self];*/ //Tried doing this too, doesn't work
[viewController viewWillAppear:YES];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
[self performSelector@selector(toggleView)];
}
viewWillAppear's of ViewController
-(void)viewWillAppear:(BOOL)animated
{
if(self.reloadArray.count !=0)
{
NSLog(@"Reload Array Not Empty!");
NSLog(@"ReloadArray: %@",self.reloadArray); // Logs out the correct information
[self.homePageTableView reloadData];
NSLog(@"Table: %@", self.homePageTableView); // Logs out as (null) :(
}
else
{
NSLog(@"Reload Array Is Empty");
}
}
Anyone have any suggestions/ideas or has anyone worked with something like this or come across this problem? If so, any information and guidance would be greatly appreciated. Thanks in advance!
Upvotes: 0
Views: 101
Reputation: 858
You can use Notification center method. In your main view controller's viewdidload method write following code..
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(anymethod:)
name: anyname
object: nil];
- (void)anymethod:(NSNotification *)notification {
NSLog(@"%@", notification.userInfo);
}
and in your right view controller pass data like,
[[NSNotificationCenter defaultCenter] postNotificationName:@"anyname" object:self userInfo:anydata];
Upvotes: 1