Mapa 클래스라고하는지도가있는보기를 여는 UITableView가 있습니다. 이 테이블 뷰에서 모든 종류의 텍스트 정보를 맵에 전달하는 데 문제가 있습니다. 내지도의 제목과 CLLocation의 좌표가 될 문자열 텍스트를 보내야합니다. 여기tableview에서지도가있는보기로 텍스트를 전달하려고 시도했습니다.
코드의 일부
MyTableView.m :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
instMapa = [[Mapa alloc] initWithNibName:@"Mapa" bundle:nil];
instMapa.mytext = @"pass text to be the title";
[self.navigationController pushViewController:instMapa animated:YES];
}
Mapa.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <MapKit/MKAnnotation.h>
@class MapViewAnnotation;
@interface Mapa : UIViewController <MKMapViewDelegate> {
IBOutlet MKMapView *mapView;
NSString *stringTitle;
NSString *mytext;
MapViewAnnotation *newAnnotation;
}
@property (nonatomic, retain) IBOutlet MKMapView *mapView;
@property (nonatomic, retain) NSString *stringTitle;
@property (nonatomic, retain) NSString *mytext;
@property (nonatomic, retain) MapViewAnnotation *newAnnotation;
@end
Mapa.m
#import "Mapa.h"
#import "MapViewAnnotation.h"
@implementation Mapa
@synthesize mapView;
@synthesize stringTitle;
@synthesize mytext;
@synthesize newAnnotation;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
CLLocationCoordinate2D location;
location.latitude = (double) 51.501468;
location.longitude = (double) -0.141596;
// Add the annotation to our map view
newAnnotation = [[MapViewAnnotation alloc] initWithTitle:mytext andCoordinate:location];
[self.mapView addAnnotation:newAnnotation];
}
// When a map annotation point is added, zoom to it (1500 range)
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
MKAnnotationView *annotationView = [views objectAtIndex:0];
id <MKAnnotation> mp = [annotationView annotation];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 1500, 1500);
[mv setRegion:region animated:YES];
[mv selectAnnotation:mp animated:YES];
}
// Received memory warning
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
// If the view unloads, release the map view
- (void)viewDidUnload {
}
- (void)dealloc {
[newAnnotation release];
[mytext release];
[stringTitle release];
[mapView release];
[super dealloc];
}
@end
MapViewAnnotation.h
01 도움을 23,516,#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface MapViewAnnotation : NSObject <MKAnnotation> {
NSString *title;
CLLocationCoordinate2D coordinate;
}
@property (nonatomic, copy) NSString *title;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d;
@end
MapViewAnnotation.m
@implementation MapViewAnnotation
@synthesize title, coordinate;
- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d {
[super init];
title = ttl;
coordinate = c2d;
return self;
}
- (void)dealloc {
[title release];
[super dealloc];
}
@end
감사합니다!
? 그것은 추락합니까? 충돌이 발생하면 정확한 충돌 메시지는 무엇입니까? – Anna
하나의 잠재적 인 문제점은 MapViewAnnotation의 'initWithTitle' 메소드에 있습니다. 'title = ttl;'줄은'mytext'가 나중에 해제 되더라도 값이 유지되도록하기 위해'title = [ttl copy];'이어야합니다. – Anna