Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To send values to parent controller you have to use protocols. I will provide proper steps you should take in order to have your desired functionality working.</p> <p>1. Create a protocol for your AddTeacherToCourseController. In your AddTeacherToCourseController.h add the following right below the imports:</p> <pre><code>@protocol AddTeacherToCourseControllerProtocol &lt;NSObject&gt; - (void)yourDelegateMethod:(Teacher *)insegnante; @end </code></pre> <p>And below interface tag add:</p> <pre><code>@property (strong, nonatomic) id &lt;AddTeacherToCourseControllerProtocol&gt; delegate; </code></pre> <p>2. In AddTeacherToCourseController.m:</p> <pre><code>-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // I would use the existing array you are using to display the teachers in order to select the correct one you want to send back like this: // Teacher *teacher = [self.teachers getTeacherInPosition:indexPath.row]; [self.delegate yourDelegateMethod:[yourTeacherArray objectAtIndex:indexPath.row]]; } </code></pre> <p>[this method will call your delegate method through the protocol and will pass your selected professor to the parent controller]</p> <p>3. In your parent controller, your newCourseViewController.h right after interface line add:</p> <pre><code>&lt;AddTeacherToCourseControllerProtocol&gt; </code></pre> <p>4. If you do not have an Insegnante button action, create one in interface builder [dragging and naming]. Then add the following to this action:</p> <pre><code>// assuming your storyboard is named MainStoryboard. here you create your segue programmatically: UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; addTeacherToCourseViewController *addTeacherController = (addTeacherToCourseViewController *)[storyBoard instantiateViewControllerWithIdentifier:@"addTeacherToCourseViewController"]; addTeacherController.delegate = self; [self.navigationController pushViewController:addTeacherController animated:YES]; </code></pre> <p>5. In Interface Builder:</p> <ul> <li>Remove your segue from Insegnante button.</li> <li>Edit the Storyboard Id of 'addTeacherToCourseViewController' to 'addTeacherToCourseViewController'</li> </ul> <p>6. In newCourseViewController.h write your delegate method:</p> <pre><code>- (void)yourDelegateMethod:(Teacher *)insegnante{ // Do whatever you want with your Insegnante // and be sure to pop the second controller from the view stack: [self.navigationController popViewControllerAnimated:YES]; } </code></pre> <p>Let me know if you have questions and if my answer helped anyone. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload