I have FirstViewController and a SecondViewController . I created a button in the FirstViewController in order to execute the modally segment before the SecondViewController .
In SecondViewController I have a tableView displaying a list of 8 elements, since I select an element from this list, I dismissViewControllerAnimated: returning to FirstViewController .
What I would like to do is pass the string back to FirstViewController .
I used this post as a reference for my code: rejectModalViewController AND pass the data back
So this is what I have:
in FirstViewController.h
#import <UIKit/UIKit.h> #import "AppDelegate.h" #import "SecondViewController.h" @interface FirstViewController : UIViewController <SecondDelegate> @end
in FirstViewController.m
in SecondViewController.h
in SecondViewController.m
#import "SecondViewController.h" @interface SecondViewController () @end @implementation SecondViewController @synthesize myDelegate; @synthesize myTableView; ... - (int)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 8; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [atributoTableView dequeueReusableCellWithIdentifier:@"MainCell"]; if(cell == nil){ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MainCell"]; } cell.textLabel.text = //strings from an array here; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if([self.myDelegate respondsToSelector:@selector(secondViewControllerDismissed:)]) { [self.myDelegate secondViewControllerDismissed:@"SOME STRING HERE"]; NSLog(@"string passed"); } [self dismissViewControllerAnimated:YES completion:nil]; NSLog(@"SecondViewController dismissed"); } @end
When I launch the application, I can switch from FirstViewController to SecondViewController , and when I select a row from the View table, I return to FirstViewController just fine. The problem is that the string βSOME LINE HEREβ was not returned.
What am I missing?
By the way, I'm not sure if this is relevant: I use ARC and Storyboards.
ios objective-c delegates uistoryboard
Juan Andres Mar 08 '13 at 19:55 2013-03-08 19:55
source share