Reputation: 3485
In my application I have 2 separate ways to get to the same UIViewController, on way is to go through 2 parent ViewControllers created using the storyboard and this way works perfectly just passing and id through each segue transition.
The other way (Which is what I need help with) goes directly from a button pressed on the RootViewController, it also just passes the id to a customly defined object called Event. The code for each transition is below:
From the segue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
Event *event = [nEventList objectAtIndex:path.row];
EventInfo *eventInfo = segue.destinationViewController; //Create new ViewController
eventInfo.eventID = event.id;
}
From the button:
- (void)FeaturedPressedAction:(id)sender
{
UIButton *button = (UIButton *)sender;
int tag = button.tag;
EventInfo *eventInfo = [[EventInfo alloc] init]; //Create new ViewController
eventInfo.eventID = @"1"; //There is an event with id '1'
[self.navigationController pushViewController:eventInfo animated:YES];
}
And the code to set up the ViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIImage *image = [UIImage imageNamed:@"title.png"];
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:image];
SingletonClass* myapp = [SingletonClass sharedInstance];
events = [myapp getEvents];
// Loop to filter out the events that Do not have this ID
Event *event;
BOOL found = false;
for (int i = 0; i < [events count]; i++) {
if(!found){
event = [events objectAtIndex:i];
if([event.id isEqualToString: eventID]){
found = true;
NSLog(@"Found the event with title %@", event.title);
}
}
}
self.eventTitle.text = event.title;
self.eventLocation.text = event.location;
self.eventDate.text = event.date;
self.eventTime.text = @"22:00";
self.eventDescription.text = event.details;
}
It finds the event fine as I can see with the NSLog's left in there, just none of the view loads when coming from the button press. Where am I going wrong?
Upvotes: 1
Views: 126
Reputation: 6058
Rather than alloc your EventInfo*
, you should instantiate it from your storyboard instead.
So in your FeaturedPressedAction
replace the initialisation line with:
EventInfo *eventInfo = [self.storyboard instantiateViewControllerWithIdentifier:@"..."];
And make sure you identify the ViewController in Interface Builder with the same identifier. Replace ... with something meaningful.
Upvotes: 2