Domanda

I'm using the didSelectRowAtIndexPath: to pass some data from a table vc to a detail vc using the code below that works fine.

What I'm trying to do is to also send this data from a map callOutAccessoryControlTapped: method but I am unsure how to send the data that way.

How would I send
detailViewController.descriptionTextViewString = [[publicDataArray objectAtIndex:indexPath.row] objectForKey:@"short_description"];
using the
callOutAccessoryControlTapped: method?

The objectAtIndex:indexPath.row is unrecognized from within the map callOutAccessoryControlTapped: method.

Here's my didSelectRowAtIndexPath: code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

    ScrollView_ExampleViewController *detailViewController = [[ScrollView_ExampleViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];

    detailViewController.latStr = [[[publicDataArray objectAtIndex:indexPath.row] objectForKey:@"address"] objectForKey:@"lat"];
    detailViewController.lngStr = [[[publicDataArray objectAtIndex:indexPath.row] objectForKey:@"address"] objectForKey:@"lng"];

    detailViewController.addressStr = [[[publicDataArray objectAtIndex:indexPath.row] objectForKey:@"address"] objectForKey:@"address"];
    detailViewController.titleStr = [[publicDataArray objectAtIndex:indexPath.row] objectForKey:@"title"];

    detailViewController.mainImageUrl = [[publicDataArray objectAtIndex:indexPath.row] objectForKey:@"image"];

    detailViewController.listingId = [[publicDataArray objectAtIndex:indexPath.row] objectForKey:@"id"];

    detailViewController.descriptionTextViewString = [[publicDataArray objectAtIndex:indexPath.row] objectForKey:@"short_description"];

    [self.navigationController pushViewController:detailViewController animated:YES];

}

Here's my map annotation calloutAccessoryControlTapped: method

- (void)mapView:(MKMapView *)mv annotationView:(MKAnnotationView *)pin calloutAccessoryControlTapped:(UIControl *)control {
    ScrollView_ExampleViewController *detailViewController = [[ScrollView_ExampleViewController alloc] initWithNibName:@"ScrollView_ExampleViewController" bundle:nil];

    MyAnnotation *theAnnotation = (MyAnnotation *) pin.annotation;

    detailViewController.titleStr = theAnnotation.title;
    detailViewController.addressStr = theAnnotation.subtitle;
    //   detailViewController.latStr = theAnnotation.latString;
    // detailViewController.lngStr = theAnnotation.lngString;

    //  detailViewController.url = theAnnotation.theUrl;

    [self.navigationController pushViewController:detailViewController animated:YES];
}
È stato utile?

Soluzione

You can use the following method to get the tableView's selected index:

NSIndexPath *selectedIndexPath = [tableView indexPathForSelectedRow];

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