当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - IOS: how to show label text value on UIMapView

问题描述:

i am working on a UITableView in which have to pass data from one view to another through StoryBoard.

data is now passing through storyboard

now i want the data i passed on the second ViewController to be display on UIMapView

i am sharing my code

.h file of first VC

{

UITableView * addresstable;

NSArray * addresses;

NSString *localStringValue;

}

.m file of first VC

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

NSUInteger row = [indexPath row];

NSString *value = [addresses objectAtIndex:row];

localStringValue = [tableView cellForRowAtIndexPath:indexPath].textLabel.text;

NSLog(@"ID is Here: %@", value);

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

detailmapViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"detailmapViewController"];

[self presentModalViewController:vc animated:YES];

vc.PassID=value; ///assign the value after presenting

}

.h file of Second view

{

UILabel *addresslbl;

NSString *PassID;

}

@property(nonatomic,retain)IBOutlet UILabel* addresslbl;

@property (weak, nonatomic) IBOutlet MKMapView *mapvw;

@property (strong, nonatomic) IBOutlet CLLocationManager *locationManger;

@property (nonatomic, retain) NSString *PassID;

.m file of second view

- (void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view.

addresslbl.text=PassID;

NSLog(@"Label is Here %@",self.PassID);

}

i also want to show the value of the label of second VC on the MAP for that i uses all the framework and delegate files

but i don't know how to call label text value for map

for that i uses the following code

self.mapvw.delegate=self;

NSString *location = //---> how to put label value here <---

CLGeocoder *geocoder = [[CLGeocoder alloc] init];

[geocoder geocodeAddressString:location

completionHandler:^(NSArray* placemarks, NSError* error){

if (placemarks && placemarks.count > 0) {

CLPlacemark *topResult = [placemarks objectAtIndex:0];

MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];

MKCoordinateRegion region = self.mapvw.region;

region.center = [(CLCircularRegion *)placemark.region center]; //placemark.region.center;

region.span.longitudeDelta /= 1800.0;

region.span.latitudeDelta /= 1800.0;

[self.mapvw setRegion:region animated:YES];

[self.mapvw addAnnotation:placemark];

}

}

];

网友答案:

The problem is, you are assigning the values the values after the viewcontroller is presented. So, it wont get the value.

Try this

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    detailmapViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"detailmapViewController"];

vc.PassID=value;

[self presentModalViewController:vc animated:YES];

and for your second question why don't you simply assigning the PassID value directly to location string

NSString *location = self.PassID;

or

NSString *location = addresslbl.text;
分享给朋友:
您可能感兴趣的文章:
随机阅读: