Domanda

I have an iPhone application that reads the details of local businesses from a .csv file. There are 3 main section:

  1. Where to Sleep
  2. Where to Eat
  3. What to Do

Depending on which one is clicked (e.g. Where to Sleep), you get a sub section of options like:

  1. B&B
  2. Hotels
  3. Caravan and Camping

Then if you select e.g. Hotels, you are shown a UITableView of the list of hotels. The UITableView has 2 sections in it to differentiate between 3 Star and 4 Star hotels. See screen grab below. enter image description here

This is all OK so far but when I click on a cell to segue to the business' details page (a UIViewController), I segue with the wrong cell information.

I have stepped throughout the code in my UITableViewController's didSelectRowAtIndexPath and it would seem that I am registering the correct selection on each cell.

As an example, in the image above, if I select Ballyroe Heights Hotel, this is the output I get when stepping through it. Where dataArray() is an NSMutableArray that holds an NSMutableArray of 3 Star and an NSMutableArray of 4 Star Hotels that are added as below.

[dataArray addObject:threeStarArray];
[dataArray addObject:fourStarArray];

Output Image

However, clicking on Ballyroe Heights Hotel displays the details for Ballygarry House Hotel and Spa

A clue to what may be going on is in the Shopping section. Below is a screen grab of what the Shopping view and sections look like.

enter image description here

Clicking on Manor West Retail Park display the correct information. But clicking on Shaws Department Store displays Manor West Retail Park again. Then clicking on Thats Perfect displays Shaws Department Store - and clicking on Sean Hussey displays Thats Perfect details. This is repeated for each section.

Clicking on Hardware (Kellihers...) stars the display again at Manor West Retail Park.

But again stepping through it, it seems that the correct cell is chosen in didSelectRowAtIndexPath().

In the example below I have selected Sean Hussey and again the output shows that the correct cell was chosen and that the segue sender:selectedCell is the Sean Hussey object.

However, the object that is passed to the UIViewController is of Thats Perfect. Can anyone see where I am going wrong? Additional code can be supplied but Im sure the issue has to lie here as this method checks for row selections and performs the segues.

enter image description here

È stato utile?

Soluzione

You are using wrong API to send data. Data is passed using prepareForSegue not performSegue

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     [self performSegueWithIdentifier:@"mySegueId" sender:self];
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSLog(@"prepareForSegue: %@", segue.identifier ); NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

if ([segue.identifier isEqualToString:@"mySegueId"] && indexPath) { NSArray *selectedRowArray = [dataArray objectAtIndex:indexpath.section]; BusinessDetailContent *selectedContent = [selectedRowArray objectAtIndex:indexpath.row]; BusinessDetailController *detailController = segue.destinationViewController; detailController.selectedcontent = selectedContent; }

}

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top