I’m having trouble sending data to a different view using the “prepareForSegue” method…
I have a tableview that’s populated with results from an sqlite query. When I tap on one of table cells it directs me to another view where I have a label that will tell me the ID and Name of the
I have a NSString that holds the value of an ID from an SQLite datasource. I want to pass that id to the second view of my app, to use it to grab information from the sqlite datasource that’s based off that id.
Now I’ve written code where it’ll pass information from one view to the other… but for some reason the information is “off count”. Here’s what I mean, I have a list of 3 mountain areas: Deception, Far Side, and Mt. Washington (listed in a tableview on the first view). When I click on Mt. Washington, it’ll go to the second view, and the label that I have setup to tell me the name of the selected cell…. is blank. I hit back button on the navigation bar, and tap Mt. Washington again, and this time the label displays the name of “Mt. Washington”. Now when I go back and click on “Far Side”, the label displays “Mt. Washington”. When I go back and click on “Far Side” again, The label changes to “Far Side”. Hopefully that makes sense.
Does any one know how to fix the problem?
Here’s the code I have:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:@"areaIDpush"]){
RockViewController *rockRoutes = [segue destinationViewController];
rockRoutes.rockID = areaID_fk;
rockRoutes.rockName = areaName_fk;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
areaID_fk = cell.detailTextLabel.text;
areaName_fk = cell.textLabel.text;
}
- (void)viewWillAppear:(BOOL)animated {
[areaIDLabel setText:rockID];
[areaNameLabel setText:rockName];
[super viewWillAppear:animated];
}
Hopefully that’ll help you see where I’m running into problems… any kind of help would be great. Thanks!
Sent my code to a buddy, and he helped me realize what was going wrong.
Here’s the right code: