Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing id from Parse table view to a detail view
    primarykey
    data
    text
    <p>(I know this has been asked before, unfortunately none of the related StackOverflow answers I've looked through and tried out while trying to figure this problem out have worked for me. Any help would be much appreciated.)</p> <p>I'm building a simple news app. The opening screen grabs the latest news entry using Parse's API.</p> <p><img src="https://i.stack.imgur.com/vg0l3.png" alt="First screen"></p> <p>And when you tap the menu button, you get a UITableView of past news days:</p> <p><img src="https://i.stack.imgur.com/QzaRr.png" alt="Sliding menu"></p> <p>I want to be able to pass the id from the selected Parse table cell back to the main view.</p> <p>I'm using ECSlidingViewController for the sliding menu and a Storyboard for the various screens:</p> <p><img src="https://i.stack.imgur.com/fvz42.png" alt="The Storyboard"></p> <p>But because of the way I'm using ECSlidingViewController, I can't figure out how to pass data via segues like I otherwise would be able to, so I'm trying to just pass it via the view controllers with a custom init.</p> <p>Here's my MainViewController.h code:</p> <pre><code>@interface MainViewController : UIViewController @property (nonatomic) NSString *detailId; - (id)initWithDetailId:(NSString*)theId; @end </code></pre> <p>Here's my <code>didSelectRowAtIndexPath</code> code in MenuViewController.m:</p> <pre><code>MainViewController *mainVC = [[MainViewController alloc] initWithDetailId:@"test"]; [self.navigationController pushViewController:mainVC animated:YES]; </code></pre> <p>Here's MainViewController.m's <code>initWithDetailId</code>:</p> <pre><code>- (id)initWithDetailId:(NSString*)theId { NSLog(@"initWithDetailId"); self = [super initWithNibName:nil bundle:nil]; if (self) { detailId = theId; } return self; } </code></pre> <p>And here's MainViewController.m's <code>viewDidLoad</code>:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; NSLog(@"detailId equals: %@", self.detailId); } </code></pre> <p>But all I get from the NSLog is "detailId equals: (null)". What am I doing wrong here? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COThe best answer for passing data between view controllers is here: http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers The basic idea is that you should create a segue between your prototype cell and the main view controller, use `prepareForSegue` to set `detailId` in the `destinationController` as discussed in that other post, and retire your current `didSelectRowAtIndexPath`.
      singulars
    2. CORob, I'd tried that before, and because of the way I'm trying to structure this app (Main view that shows 1 view by default, and then you access the Menu for the table view), I don't have a Navigation Controller. Do I not need one in order to use segues? If I remember correctly I was getting an error when I tried `prepareForSegue` before, saying I needed a Nav Controller.
      singulars
    3. COYou may be confusing two completely separate issues. Whether you use segues has nothing to do with whether you use navigation controller. You need navigation controller if you want to use a _push_ segues, though. (You also need nav controller if you use `pushViewController` like your code above!) If you use modal segues, though, no nav controller needed (and, in code, you'd present/dismiss controllers rather than push/pop controllers). I argue for segues because it visually represents the flow of your app, and it simplifies the code.
      singulars
 

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