我是iOS編程新手,在視圖控制器之間傳遞數據時遇到問題。如何將註釋標題傳遞給另一個視圖控制器
我有一個視圖控制器,在地圖視圖上對地圖註釋進行地理編碼,並將地址設置爲註釋視圖的標題。註解視圖具有一個標註按鈕,將另一個視圖推送到具有標籤的堆棧,並且我希望將經過地理編碼的地址顯示爲標籤。下面是一些代碼:
這是我把針:
-(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];
}
}
}];
}
這裏是我想要的地址顯示視圖代碼:
#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有一個標題屬性和字幕屬性。當PinViewController被推到堆棧頂部時,我嘗試將標籤的文本設置爲該標籤的標題,但標籤不顯示任何文本。有人能幫助我,並告訴我我失蹤了嗎?非常感謝您的幫助。
你不顯示在您創建銷視圖控制器代碼,設置其引腳並推到導航堆棧。 – jrturton
當你想在標籤上顯示標題...點擊插針或揭示按鈕後...? – Rajneesh071
我想在PinViewController的標籤上按下披露按鈕後顯示標題。 –