gpt4 book ai didi

iphone - 如何将注释标题传递给另一个 View Controller

转载 作者:行者123 更新时间:2023-11-28 20:29:05 25 4
gpt4 key购买 nike

我是 iOS 编程的新手,我在 View Controller 之间传递数据时遇到了问题。

我有一个 View Controller ,它对 map View 上的注释进行地理编码,并将地址设置为注释 View 的标题。注释 View 有一个标注按钮,可将另一个 View 推送到堆栈,该堆栈有一个标签,我希望经过地理编码的地址显示为标签。这是一些代码:

这是我放下图钉的地方:

-(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];
}
}
}];
}

这是我希望显示地址的 View 的代码:

#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 被推到堆栈顶部时,我尝试将标签的文本设置为图钉的标题,但标签不显示任何文本。有人可以帮助我并告诉我我缺少什么吗?非常感谢您的帮助。

最佳答案

你必须为这个问题分享更多的代码块:)。而不是你必须更多地了解面向对象程序中的通信

您可以阅读有关在 View 类之间传递数据的好教程 here

阅读在两个 View 之间传递对象的最佳方式 here

我在 Developer.apple 中找到了一份关于 CommunicatingWithObjects 的好文档

还可以看个好视频here

关于iphone - 如何将注释标题传递给另一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12928053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com