-1

I'm using Xcode to write an app in objective c. I am trying to pass data from a container view controller to the parent view controller using delegation. I have successfully passed the data to the parent view controller, but all of the documentation sets what I have sent to the .h header file in the .m implementation file using viewDidLoad or viewDidAppear. I was wondering, since the view is already present, if there is a way to detect that data has been changed in a view and automatically run a method or code to update the view with the new information. Something along the idea of didReceiveNewData or didEditExistingValues (of course those arent real methods). Thank you for your help!

Edit: What I have done so far:

I want to pass the data from MainFeedTableViewController to MainFeedViewController (The first is in a container inside of the second). I want to set the title of the custom navigation bar in MainFeedViewController to something described in the MainFeedTableViewController.

In the MainFeedTableViewController.m (the view sending data) I have:

#import "MainFeedTableViewController.h"
#import "FeedViewController.h"

@interface MainFeedTableViewController ()

@end

@implementation MainFeedTableViewController

- (IBAction)swipeLeftDetected:(UIGestureRecognizer *)sender {
    UIStoryboard *mc = self.storyboard;
    FeedViewController *fv = [mc instantiateViewControllerWithIdentifier:@"FeedViewController"];
    fv.navigationBarTitleToSet = @"HOPING TO SET TITLE TO THIS";
    [self performSegueWithIdentifier:@"MainToLocalFeed" sender:self];
}
and some other unrelated stuff..

In the MainFeedTableViewController.h I have:

#import <UIKit/UIKit.h>

@interface MainFeedTableViewController : UITableViewController

@end

In the MainFeedViewController.m (the one receiving the data) I have:

#import "FeedViewController.h"

@interface FeedViewController () <UINavigationBarDelegate>
@property (weak, nonatomic) IBOutlet UINavigationBar *navigationBar;

@end

@implementation FeedViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)setNavigationBarTitle:(NSString *)navigationBarTitle{
    self.navigationItem.title = navigationBarTitle;
}

And in the MainFeedViewController.h I have:

#import <UIKit/UIKit.h>

@interface FeedViewController : UIViewController

@property NSString *navigationBarTitleToSet;

@end

I want to run the setNavigationBarTitle method with either data from the .h (navigationBarTitleToSet) or just from the sending view controller, if possible to run a method with delegation. Thanks a ton and I hope this is possible :)

  • Yes.. a delegate the invokes a method. Show us what you have so far. And exactly where you're getting stuck. – Robert J. Clegg Jan 11 '15 at 07:53
  • @Tander I'm not sure if stack overflow notifies you, but I editted the post to show my code so far! – Matt Goodrich Jan 11 '15 at 08:09
  • A delegate is overkill just to set the title of the presenting VC. Why not use the preParForSegue method to get the correct instance of the presenting VC and then set it's title? – Robert J. Clegg Jan 11 '15 at 08:44
  • You know that feeling when you can't find something, and after like 3 solid hours you release it's in your hand? Well that just happened with this. But thanks :) – Matt Goodrich Jan 11 '15 at 09:32
  • Did you come right? Or still need some more help with this? – Robert J. Clegg Jan 11 '15 at 09:33
  • Yes it worked perfectly! Thank you for reposing the idea of the view navigation, it worked eventually, however I figured out I needed to add a second navigation controller to account for the container view. But it's perfect now :) – Matt Goodrich Jan 11 '15 at 12:09

1 Answers1

0

It turns out I needed to add a second navigation bar to account for the container view, allowing me to navigate around the current stack with the parentViewController method and then navigationItem.title. For anyone who happens to find this with a container, make sure you add one immediately after the embed segue. I'm still not sure if you can use methods through delegation, but I can't ponder any situations where it would be necessary anymore, due to viewDidLoad. Thanks to @Tander for the help!