Ios 尝试将文本从tableview传递到具有映射的视图

Ios 尝试将文本从tableview传递到具有映射的视图,ios,uitableview,map,title,Ios,Uitableview,Map,Title,我有一个UITableView,它打开一个带有地图的视图,我称之为Mapa类。我无法将任何类型的文本信息从此表视图传递到地图。我需要发送一个字符串文本作为我地图的标题和位置的坐标 这是代码的一部分 MyTableView.m: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { instMapa = [[Mapa alloc] initWithNib

我有一个UITableView,它打开一个带有地图的视图,我称之为Mapa类。我无法将任何类型的文本信息从此表视图传递到地图。我需要发送一个字符串文本作为我地图的标题和位置的坐标

这是代码的一部分

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

谢谢你的帮助

从你的问题中,我明白了这一点;您需要将所选表格视图单元格的字符串值传递给地图视图。 为此,您需要在
didSelectRowAtIndexPath
中编写此代码

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

谢谢你的快速回答。但是它不起作用,问题是我不能用我的map将任何类型的参数(如字符串)从tableview传递到Mapa实例;在instMapa.mytext=@“将文本作为标题传递”之前;告诉我发生了什么。你把我的文本的NSLog放到viewdiload中了吗?是的。问题一定出在我的tabbar上。我也试着用其他类传递参数,但它不起作用。当你选择一行时会发生什么?它会崩溃吗?如果崩溃,确切的崩溃消息是什么?MapViewAnnotation中的
initWithTitle
方法中存在一个潜在问题。行
title=ttl应该是
title=[ttl copy]
以确保即使以后发布了
mytext
,该值仍保持不变。
#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
@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
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
 instMapa.mytext = cell.textLabel.text;