Question

Hi i have a problem. I have 2 viewcontroller, in the first there is a mapView that implements the function "calloutAccessoryControlTapped" to tap a button on an annotation on the mapView; in the second there is just a UITextView. I want to change the text of the UITextView (and show the SecondViewController) in the second controller once the button on annotation is clicked; here is my code

(FirstViewController)

Header

@interface FirstViewController<MKMapViewDelegate>{ 
IBOutlet MKMapView *mapView;
SecondViewController *secondV;}
@end

Implementation

@implementation FirstViewController

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
secondV = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
NSString *myS = @"some text here";
[secondV.myTextView setText:myS];

//Switch from this to the secondview [self presentModalViewController:secondV animated:YES]; @end

(SecondViewController)

Header

@interface SecondViewController{ 
IBOutlet UITextView *myTextView;
}

@property(nonatomic, retain)UITextView *postitTextView;
- (IBAction)backToMAp;
- (void)setText:(NSString *)string;
@end

Implementation

@implementation SecondViewController

- (IBAction)backToMAp{

//Back To First View; [self dismissModalViewControllerAnimated:YES];}

- (void)setText:(NSString *)string{ 
myTextView.text = string;}

In this code when i tap on the button ([self presentModalViewController:secondV animated:YES];) on annotation the first time the second view show up but the text of UITextView don't change, when i back on the FirstView ([self dismissModalViewControllerAnimated:YES];) and then again tap the button to switch again to secondView the text of UITextView change.....

Sorry for long thread and for my bad english!!

Thank you stack!

Was it helpful?

Solution 2

I forget to set myTextView as @property:

@property(nonatomic, retain)UITextView *myTextView;

and i forget to insert the @syntesize in the implementation:

@syntesize myTextView;

OTHER TIPS

You have two UITextViews in your code: myTextView and postitTextView. In IB have you got the right one in the your UIView?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top