简体   繁体   English

如何将注释标题传递给另一个视图控制器

[英]How to pass annotation title to another view controller

I am new to iOS programming, and I am having trouble with passing data between view controllers. 我是iOS编程的新手,并且在视图控制器之间传递数据时遇到麻烦。

I have a view controller that geocodes an annotation on a map view, and sets the address as the title of the annotation view. 我有一个视图控制器,可对地图视图上的注释进行地址解析,并将地址设置为注释视图的标题。 The annotation view has a callout button that pushes another view to the stack, which has a label, and I want the address that was geocoded to show up as the label. 批注视图具有一个标注按钮,该标注按钮将另一个视图推送到具有标签的堆栈中,我希望将经过地理编码的地址显示为标签。 Here is some code: 这是一些代码:

This is where I drop the pin: 这是我放针的地方:

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

Here is the code for the view where I want the address to show up: 这是我要显示地址的视图的代码:

#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]];

}

The class MapPoint has a title property and subtitle property. MapPoint类具有title属性和subtitle属性。 When the PinViewController is pushed to the top of the stack, I try to set the text of the label to the title of the pin, but the label does not show any text. 当PinViewController被推到堆栈的顶部时,我尝试将标签的文本设置为引脚的标题,但是标签不显示任何文本。 Can someone help me out and tell me what I am missing? 有人可以帮我一下,告诉我我想念什么吗? Your help is greatly appreciated. 非常感谢您的帮助。

You must share more code blocks for this question :) . 您必须为此问题共享更多代码块:)。 instead of you have to get more idea about Communication in Object-Oriented Programs 而不是您必须对面向对象程序中的通信有更多的了解

You can read a good tutorial about Passing Data Between View Classes here 您可以在此处阅读有关在视图类之间传递数据的很好的教程。

Read best way to pass an object between two views here 此处阅读在两个视图之间传递对象的最佳方法

There is a good document that i found in Developer.apple regarding CommunicatingWithObjects 我在Developer.apple中找到了一份关于CommunicatingWithObjects的好文档。

Also you can watch a good video here 您也可以在这里观看精彩的视频

Just create property for the label and pass the label text from callout tapped method 只需为标签创建属性,然后从标注的点击方法中传递标签文本

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使MKMapKit中的注释中的标注按钮转到另一个视图控制器 - How to make the callout button in an annotation in MKMapKit go to another view controller 如何在IOS中将数据从一个视图传递到另一个视图控制器? - How to pass data from one view to another view controller in IOS? 如何将信息从一个视图控制器中的表视图单元传递到另一视图控制器? - How do I pass information from a table view cell in one view controller to another view controller? 单击注释后,如何将数据传递到其视图控制器? - When a annotation is clicked how can I pass data to its view controller? 如何将数组从一个视图 controller 传递到另一个视图? - How to pass an array from one view controller to another? 如何使用委托将数据从一个视图控制器传递到另一个视图控制器? - how to use delegate to pass data to from one View Controller to another? 如何将单元格中的第三个值传递给另一个表视图控制器 - How to pass a third value in a cell to another table view controller 如何将变量从一个视图控制器传递到另一个? - How to pass a variable from one view controller to another? 如何将UI ImageView从一个视图控制器传递到另一个? 迅捷3 - how to pass a UI ImageView from one view controller to another? swift 3 如何将字符串值从一个视图控制器传递到另一个视图控制器 - how to pass a string value from one view controller to another view controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM