2012-10-17 2 views
0

iOS 프로그래밍을 처음 사용하고보기 컨트롤러간에 데이터를 전달하는 데 문제가 있습니다.주석 제목을 다른보기 컨트롤러에 전달하는 방법

지도보기에서 주석을 지오 코딩하고 주소를 주석보기의 제목으로 설정하는보기 컨트롤러가 있습니다. 주석보기에는 레이블이있는 다른보기를 스택에 푸시하는 설명 선 단추가 있으며 지오 코딩 된 주소를 레이블로 표시하려고합니다.

#import <UIKit/UIKit.h> 
@class MapPoint; 

@interface PinViewController : UIViewController <UINavigationControllerDelegate,  UIImagePickerControllerDelegate,UITextFieldDelegate> 

{ 
    __weak IBOutlet UILabel *addressLabel; 
} 

@property (weak, nonatomic) IBOutlet UIImageView *imageView; 
@property (strong, nonatomic) MapPoint *pin; 

-(void)takePicture:(id)sender; 
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; 

@end 

#import "PinViewController.h" 
#import "MapPoint.h" 

@interface PinViewController() 

@end 

@implementation PinViewController 

@synthesize imageView, pin; 
-(void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 

    [addressLabel setText:[pin title]]; 

} 

클래스를 MapPoint : 여기

-(void)press:(UILongPressGestureRecognizer *)recognizer 
{ 
    CGPoint touchPoint = [recognizer locationInView:worldView]; 
    CLLocationCoordinate2D touchMapCoordinate = [worldView convertPoint:touchPoint toCoordinateFromView:worldView]; 

    geocoder = [[CLGeocoder alloc]init]; 
    CLLocation *location = [[CLLocation alloc]initWithCoordinate:touchMapCoordinate 
                altitude:CLLocationDistanceMax 
              horizontalAccuracy:kCLLocationAccuracyBest 
              verticalAccuracy:kCLLocationAccuracyBest 
                timestamp:[NSDate date]]; 
    [geocoder reverseGeocodeLocation:location 
        completionHandler:^(NSArray *placemarks, NSError *error) { 
         NSLog(@"reverseGeocoder:completionHandler: called"); 
         if (error) { 
          NSLog(@"Geocoder failed with error: %@", error); 
         } 
         if (placemarks && placemarks.count > 0) 
         { 
          CLPlacemark *place = [placemarks objectAtIndex:0]; 
          _address = [NSString stringWithFormat:@"%@ %@, %@ %@", [place subThoroughfare], [place thoroughfare], [place locality], [place administrativeArea]]; 

          if (UIGestureRecognizerStateBegan == [recognizer state]) { 
           _addressPin = [[MapPoint alloc]initWithCoordinate:touchMapCoordinate 
                     title:_address]; 
          [worldView addAnnotation:_addressPin]; 
         } 
        } 
       }]; 
} 

내가 주소를 표시 할 뷰의 코드입니다

이 내가 핀을 놓는 위치입니다 : 여기에 몇 가지 코드입니다 title 속성과 subtitle 속성이 있습니다. PinViewController 스택의 맨 위로 밀어 때 레이블의 텍스트를 핀 제목으로 설정하려고하지만 레이블을 모든 텍스트를 표시하지 않습니다. 누군가 나를 도우 려하고 제가 누락 된 부분을 말해 줄 수 있습니까? 귀하의 도움을 크게 주시면 감사하겠습니다.

+1

, 그 핀을 설정 선 탭 방식의 레이블 텍스트 및 탐색 스택에 밀어 넣습니다. – jrturton

+0

핀 또는 공개 버튼을 클릭 한 후 라벨에 제목을 표시하려고 할 때 ...? – Rajneesh071

+0

PinViewController의 레이블에서 공개 버튼을 누른 후 제목을 표시하려고합니다. –

답변

1

는 그냥 레이블 속성을 만들고 통과 당신은 핀 뷰 컨트롤러를 만드는 코드를 표시하지 않습니다

- (void)mapView:(MKMapView *)mapView annotationView:(MKPinAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { 

    Details *det=[[Details alloc]init]; 
    det.label.text=annotation.title; 
    [self.navigationController pushViewController:det animated:YES]; 
    [det release]; 
} 
+0

이 메서드를 구현했지만 설명 선 단추를 누르면 내 응용 프로그램이 충돌합니다. 오류가 발생했습니다 exc_bad_access code = 1 –

+0

사용자 지정 메서드를 구현할 때 응용 프로그램이 중단되지는 않지만 작동하지 않습니다. 방법은 다음과 같습니다.'- (void) showDetails : (id) 보낸 사람 { NSLog (@ "주석을 위해 탭된 액세서리 버튼"); PinViewController * pinViewController = [[PinViewController alloc] init]; pinViewController.label.text = _addressPin.title; [[네비게이션 컨트롤러] pushViewController : pinViewController animated : YES]; }' –

2

이 질문에 더 많은 코드 블록을 공유해야합니다. :). 당신이 더 많은 아이디어를 얻을 필요가 대신 당신은 뷰 클래스 사이 here

읽기 가장 좋은 방법은 데이터 전달에 대한 좋은 튜토리얼을 읽을 수

객체 지향 프로그램에 대한 통신은 두 가지보기 here

사이에 개체를 전달합니다

또한 당신이 좋은 비디오 here

0을 볼 수 CommunicatingWithObjects

에 관한 내가 Developer.apple에서 발견 좋은 문서가있다

관련 문제