1
votes

I am using Split View Controller. For master I have Navigation Controller with Table View Controller as a root view. For details I have Navigation Controller with Custom View Controller as a root view. From master I am selecting tableView row and displaying row details in details view. From details view i can edit details of this row using another View Controller with modal segue. The question is: How can I refresh tableView (master) after saving changes in details editing view (modal). When I tap save button the -(IBAction) unwindEditRow:(UIStoryboardSegue *)segue (of details) is triggered.

1
Use delegate pattern. - Neil Galiaskarov
I am really new to iOS/Objective-C programming. It is my first day ;) more detailed answer will be appreciated - Woo

1 Answers

2
votes

You have a lot of ways to send messages to ViewController when particular event has happened.

The first method: Use delegation pattern. What is delegate? Delegation is a clean and simple way of connecting objects and helping them to communicate with other. In other words, delegation is a dating service for Objective-C objects. :) There are some useful links: Basic concepts in Objective-C, Writing your own custom delegate Here is the way of declaring your new protocol:

@protocol DetailViewControllerDelegate <NSObject>

-(void)itemHasBeenChanged:(id)edittedObject;

@end

In your DetailViewController declare your future delegate:

@property (weak,nonatomic) MasterViewController <DetailViewControllerDelegate> *delegate;

Implement itemHasBeenChanged: method in MasterViewController.m:

  -(void)itemHasBeenChanged:(id)edittedObject{
    //editting logic goes here
  }

Tell our class to implement the DetailViewControllerDelegate protocol so that it knows which functions are available to it by line:

@interface MasterViewController : UITableViewController <DetailViewControllerDelegate>

After all these steps, you can call method in your DetailViewController whenever you want by:

[self.delegate itemHasBeenChanged:yourObject];

Here is my example code on github

Second way

We can use NSNotificationCenter as an alternative to custom protocols. Making custom protocols and registering methods is hard to do in a big project and NSNotificationCenter can free us from that burden. The main approach used with NSNotificationCenter is that any object can send a notification to the notification center and at the same time any other object can listen for notifications on that center.