嗨我有问题。我有2个viewcontroller,第一个是mapView,它实现了函数“calloutAccessoryControlTapped”来点击mapView上注释的按钮; 在第二个只有一个UITextView。 我想在单击注释上的按钮后更改第二个控制器中的UITextView文本(并显示SecondViewController);这是我的代码
(FirstViewController)
标题
@interface FirstViewController<MKMapViewDelegate>{
IBOutlet MKMapView *mapView;
SecondViewController *secondV;}
@end
实施
@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];
//从此切换到第二个视图 [self presentModalViewController:secondV animated:YES]; @end
(SecondViewController)
标题
@interface SecondViewController{
IBOutlet UITextView *myTextView;
}
@property(nonatomic, retain)UITextView *postitTextView;
- (IBAction)backToMAp;
- (void)setText:(NSString *)string;
@end
实施
@implementation SecondViewController
- (IBAction)backToMAp{
//返回第一视图; [self dismissModalViewControllerAnimated:YES];}
- (void)setText:(NSString *)string{
myTextView.text = string;}
在这段代码中我点击按钮([self presentModalViewController:secondV animated:YES];)注释时第一次显示第二个视图但UITextView的文本没有改变,当我回到FirstView时([self dismissModalViewControllerAnimated:YES];)然后再次点击按钮再次切换到secondView UITextView的文本更改.....
对不起长线程和我糟糕的英语!!
谢谢堆叠!
答案 0 :(得分:0)
您的代码中有两个UITextView:myTextView和postitTextView。在IB你有没有在你的UIView中找到合适的人?
答案 1 :(得分:0)
我忘记将myTextView
设为@property
:
@property(nonatomic, retain)UITextView *myTextView;
我忘了在实现中插入@syntesize
:
@syntesize myTextView;