MKMapView показва DetailView - Как да направите сегей

Имам MapView, анотациите идват от списък със свойства. Сега бих искал да видя повече данни в детайлния изглед. За съжаление не знам как да програмирам Segue, така че данните да могат да се показват. Надявам се разбирате какво имам предвид. Английският ми не е толкова добър ... Знам, че липсват някои в метода pripraveforSegue. Използвам сценарий. Предварително ви благодаря за помощта...поздрави

#import "MapViewNewController.h"
#import "MapViewAnnotation.h"
#import "SetCardController.h"



@interface MapViewNewController ()



@end

@implementation MapViewNewController 


@synthesize recipesDictionary = _recipesDictionary;

@synthesize mapView;
@synthesize locationManager;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}



- (void)viewDidLoad
{
    [super viewDidLoad];

    self.mapView.delegate = self;

    [self.mapView setShowsUserLocation:YES];


    MKCoordinateRegion newRegion ;
    newRegion.center.latitude = 50.080635;
    newRegion.center.longitude = 8.518717;
    newRegion.span.latitudeDelta = 15.5;
    newRegion.span.longitudeDelta = 15.5;
    [mapView setRegion:newRegion animated:YES];



    NSString *path = [[NSBundle mainBundle] pathForResource:@"Rezepte" ofType:@"plist"];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
    NSArray *anns = [dict objectForKey:@"myRecipes"];
    for(int i = 0; i < [anns count]; i++) {
        float realLatitude = [[[anns objectAtIndex:i] objectForKey:@"latitude"] floatValue];
        float realLongitude = [[[anns objectAtIndex:i] objectForKey:@"longitude"] floatValue];

        MapViewAnnotation *myAnnotation = [[MapViewAnnotation alloc] init];
        CLLocationCoordinate2D theCoordinate;
        theCoordinate.latitude = realLatitude;
        theCoordinate.longitude = realLongitude;
        myAnnotation.coordinate = theCoordinate;
        myAnnotation.title = [[anns objectAtIndex:i] objectForKey:@"blogname"];
        myAnnotation.subtitle = [[anns objectAtIndex:i] objectForKey:@"blogger"];
        [mapView addAnnotation:myAnnotation];


    }      

}


-(MKAnnotationView *)mapView:(MKMapView *)view viewForAnnotation:(id<MKAnnotation>)annotation {
    MKPinAnnotationView *pin = nil;

    if ([annotation isKindOfClass:[MapViewAnnotation class]]) {
        NSString *pinIdentifier = @"myPin";


        pin = (MKPinAnnotationView*)[view dequeueReusableAnnotationViewWithIdentifier:pinIdentifier];
        if (!pin) {


            pin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pinIdentifier];

            pin.image = [UIImage imageNamed:@"pin2.png"];
            pin.canShowCallout = YES;

            pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];


        }
            }

    return pin;
}



//if Button pressed
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{

     [self performSegueWithIdentifier:@"showPinDetails" sender:self];




    }

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([segue.identifier isEqualToString:@"showPinDetails"]) {

       // SetCardController *scc = [segue destinationViewController];


    }
}

person user1355961    schedule 31.07.2012    source източник


Отговори (3)


Когато performSegueWithIdentifier:sender от извикване в annotationView:view, подателят може да бъде свойството view.annotation, което уникално идентифицира извикването, което потребителят току-що е докоснал.

person Hackless    schedule 18.05.2013

Вярвам, че не сте задали идентификатора за Segue в Interface Builder. Опитах вашия код и той работи за мен (Xcode 4.4 iOS 5.1 SDK)

person Daniel    schedule 09.08.2012

Горните два отговора помагат, но не ви помагат да идентифицирате уникалните подробности за пинове, които предполагам, че са част от вашия p-списък.

Всички изгледи наследяват свойството на етикет. Той може да използва това за задържане на щифт индекс (или ключ) и следователно да го предаде на целевия View Controller, за да идентифицира уникално данните, които държите.

Тъй като вашият бутон в изгледа за извикване наследява от изгледа, можете да го маркирате и да подадете индекса, когато е активен в метода didselectAnnotationView. Използваният оператор if демаркира щифта за местоположението на потребителя.

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{

if (![(PointAnnotation *)view.annotation isKindOfClass:[MKUserLocation class]])
{
    PointAnnotation *myAnn = (PointAnnotation *)view.annotation;

    detailButton.tag = myAnn.pinIndex;
    NSLog (@"Pinindex = %d", myAnn.pinIndex);
}



}

DetailButton.tag вече може да се използва като параметър при избор на segue.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Post data to destination VC

if ([[segue identifier] isEqualToString:@"clubsToDetail"])
{


    ClubsMasterData *current = [[ClubsMasterxmlParser ClubsMasterDatas] objectAtIndex:detailButton.tag];


    ClubsDetailViewController *DVC = [[ClubsDetailViewController alloc] init];
    DVC = [segue destinationViewController];


    DVC.linkURL =  current.linkURL;
    DVC.distance = current.distance;

}
}

Тук индексирах масив, а не Plist, но принципът е същият.

person John Jamieson    schedule 15.07.2013