Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Rather than using a storyboard segue to push another view controller, try setting a protocol in your "add" view controller. Then set your "main" view controller as the delegate and handle the adding there. From there you can connect the "add" button to call the delegate method and pop the view controller.</p> <h3>LSNewListViewController.h</h3> <pre><code>@protocol LSNewListViewControllerDelegate; @interface LSNewListViewController : UIViewController @property (nonatomic, weak) id &lt;LSNewListViewControllerDelegate&gt; delegate; @end @protocol LSNewListViewControllerDelegate &lt;NSObject&gt; @optional - (void)didAddToList:(NSString*)item; @end </code></pre> <h3>LSNewListViewController.m</h3> <pre><code>@implementation LSNewListViewController // Hooked up to the Add button in the storyboard (touchUpInside) - (IBAction)addToListAction:(id)sender { if ([self.delegate respondsToSelector:@selector(didAddToList:)]) { [self.delegate didAddToList:[sourceView listName] text]]; } } @end </code></pre> <h3>LSMainViewController.h</h3> <pre><code>#import "LSNewListViewController.h" @interface LSMainViewController : UIViewController &lt;LSNewListViewControllerDelegate&gt; @end </code></pre> <h3>LSMainViewController.m</h3> <pre><code>@implementation LSMainViewController - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { LSNewListViewController *destView = [segue destinationViewController]; destView.delegate = self; } // Delegate method - (void)didAddToList:(NSString*)item { NSLog(@"Adding %@", listName); [self.listArray addObject:listName]; [self.tableView reloadData]; [self.navigationController popViewControllerAnimated:YES]; } @end </code></pre>
 

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