(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.)
I'm building a simple news app. The opening screen grabs the latest news entry using Parse's API.
And when you tap the menu button, you get a UITableView of past news days:
I want to be able to pass the id from the selected Parse table cell back to the main view.
I'm using ECSlidingViewController for the sliding menu and a Storyboard for the various screens:
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.
Here's my MainViewController.h code:
@interface MainViewController : UIViewController
@property (nonatomic) NSString *detailId;
- (id)initWithDetailId:(NSString*)theId;
@end
Here's my didSelectRowAtIndexPath
code in MenuViewController.m:
MainViewController *mainVC = [[MainViewController alloc] initWithDetailId:@"test"];
[self.navigationController pushViewController:mainVC animated:YES];
Here's MainViewController.m's initWithDetailId
:
- (id)initWithDetailId:(NSString*)theId
{
NSLog(@"initWithDetailId");
self = [super initWithNibName:nil bundle:nil];
if (self) {
detailId = theId;
}
return self;
}
And here's MainViewController.m's viewDidLoad
:
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"detailId equals: %@", self.detailId);
}
But all I get from the NSLog is "detailId equals: (null)". What am I doing wrong here? Thanks!