0
votes

EDIT: I have fixed this problem. The code is corrected to show this fix.

I have an app that uses a UITableViewController that displays a list of all 50 states separated into sections alphabetically. I have added the detail disclosure button to the prototype cell in the storyboard and the table displays all the correct information.

When I press the button on a cell, it should segue to a new viewController and display the name of the state as the view title and then display a picture of the license plate in the view.

I am using the -(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath method to control the button press and then I am using the -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender to control the values being passed to the new viewController.

The problem I am having is that when I press the detail disclosure button nothing gets passed. NSLogging the values in the new viewController outputs (null), (null) and the view has no title or picture. However, when I press back and then press the same cell's detail disclosure button a second time, it works like it should. The title is correct and the picture displays properly.

The same is true when I choose another cell, the viewController displays the last information sent and I have to press back and then choose the cell again for it to update. When choosing a different cell for the first time, (null, (null) is what the NSlog is outputting. So I believe what is happening is that the first time a detail disclosure button is pressed, no values are passed, but the second time it is pressed, the values are being passed.

Here is the relevant code:

-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
    //Don't even use this method now.
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UITableViewCell *cell = (UITableViewCell*)sender;  //Added this line
self.path = [self.tableview indexPathForCell:cell]; //Added this line

if ([segue.identifier isEqualToString:@"stateSegue"])
    {
        self.controller = segue.destinationViewController;
        self.controller.stateName = [self.stateArray[indexPath.section][indexPath.row]stateName];
        self.controller.licensePlateURL = [self.stateArray[indexPath.section][indexPath.row]licensePlateURL];
    }
}

Any help with this would be greatly appreciated.

1

1 Answers

0
votes

Check which method fires first. Maybe you set properties after segue is performed.

There's no informations about how (when) do you perform segue.

You could add this line to your accessoryButton method:

[self performSegueWithIdentifier:yourIdentifierFromStoryboard sender:self];