2012-07-04 4 views
0

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 

감사합니다!

+0

? 그것은 추락합니까? 충돌이 발생하면 정확한 충돌 메시지는 무엇입니까? – Anna

+0

하나의 잠재적 인 문제점은 MapViewAnnotation의 'initWithTitle' 메소드에 있습니다. 'title = ttl;'줄은'mytext'가 나중에 해제 되더라도 값이 유지되도록하기 위해'title = [ttl copy];'이어야합니다. – Anna

답변

0

질문에, 나는 그것을 이해합니다. 선택한 테이블 뷰 셀의 문자열 값을 맵보기에 전달해야합니다. 당신이 당신의 didSelectRowAtIndexPath이 코드를 작성할 필요가 들어 , 당신이 행을 선택하면 정확히 어떻게됩니까

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
instMapa.mytext = cell.textLabel.text; 
+0

빠른 답변을 보내 주셔서 감사합니다. 하지만 그것은 작동하지 않습니다, 문제는 내가 내 tableview에서 Mapa 인스턴스로 내 맵과 함께 어떤 종류의 인수 (문자열과 같은)를 전달할 수 없다는 것입니다. – user1033674

+0

mapa.h의 코드를 넣을 수 있습니까 –

+0

코드를 변경하고 – user1033674

관련 문제