The direction you should take is precisely this one you have found, through protocol. It is very simple and this is independent whether it is TableViewController
or not.
Let's say you have PrimeiraViewController
and SegundaViewController
. In this second, in your header file .h , we created the protocol (before the declaration @interface ):
@protocol SegundaViewDelegate <NSObject>
@required
- (void)foo:(id)bar;
@end
And in this same file, the property:
@property (nonatomic, retain) id<SegundaViewDelegate> segundaViewDelegate;
In the .m implementation file, wherever you pass this value, you call this method:
[self.segundaViewDelegate foo:[NSDate date]]
Here, I've just passed an example%, of course, of course, but you can create your method as and where you want, in your case it will be when a cell is pressed.
In NSDate
, we add this delegate in .h :
@interface PrimeiraViewController : UIViewController <SegundaViewDelegate>
And when the second screen is triggered, we define this delegate :
SegundaViewController *viewController = [[SegundaViewController alloc] init];
[viewController setSegundaViewDelegate:self];
And we implemented the method that we will receive the information:
- (void)foo:(id)bar {
NSLog("%@", bar);
}
See if you can understand and implement this way.