so currently I have a tableviewcontroller that gets presented modally above the loginviewcontroller if a certain case occurs, then once the user presses on a cell, the title should be passed to the parent view controller.
So picture (A) being the parent - the mainview, (B) being the login, and (C) being the tableviewcontroller...
C sits on top of B which sits on top of A, NOT THROUGH A NAVIGATION STACK BUT THROUGH A MODAL STACK. So C doesn't have any reference to A other than this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self Login];
[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
When a user presses on a cell, the view then goes straight to (A), so from (C) to (A) skipping (B). This is what I wanted... But the issue is how do I pass data to (A) without having to instantiate (A) again? I mean instantiate again by, it's already instantiated in the beginning of the app launch and (B) is presented over (A) if the user isn't already logged in. So (A) is ALWAYS loaded, but how do I pass data to it?
If there is more information that should be provided, please inform me and i'll edit ASAP.
EDIT I looked at a few more questions that related to this one, would I use NSNotification? Or delegation? I attempted to use both but none really worked... I refered to my previously answered question on delegation to implement the delegation solution but I have to instantiate (C) in (A). But I already instantiate (C) in (B). Heres the delgation solution I was gonna use but didn't: Delegation. Here is the Link for the NSNotification solution i attempted to use:
Put this in your parent controller in viewDidLoad
- (void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self makeCallbacks];
// get register to fetch notification
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(yourNotificationHandler:)
name:@"MODELVIEW DISMISS" object:nil];
}
//Now create yourNotificationHandler: like this in parent class
-(void)yourNotificationHandler:(NSNotification *)notice{
str = [notice object];
}
Put following to your child class where
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSLog(@"%@", cell.textLabel.text);
// cell.textLabel.text logs this -> EDF ENRS
[[NSNotificationCenter defaultCenter] postNotificationName:@"MODELVIEW DISMISS" object:cell.textLabel.text];
[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
When I log 'str' (null) is printed
Now the issue is when I log str outside of the notification later in viewWillAppear, it keeps returning null.... It only DOESNT return null when I log str within the notification method... I'll try to figure this out later but the primary issue is i guess solved using NSNotificationCenter.