1

嗨我有一个问题。我有2个viewcontroller,第一个有一个mapView,它实现了“calloutAccessoryControlTapped”函数来点击mapView上注释上的按钮;在第二个中只有一个 UITextView。单击注释上的按钮后,我想在第二个控制器中更改 UITextView 的文本(并显示 SecondViewController);这是我的代码

(第一视图控制器)

标题

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

//从这个切换到secondview [self presentModalViewController:secondV animated:YES]; @结尾

(第二视图控制器)

标题

@interface SecondViewController{ 
IBOutlet UITextView *myTextView;
}

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

执行

@implementation SecondViewController

- (IBAction)backToMAp{

//返回第一个视图;[自我dismissModalViewControllerAnimated:是];}

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

在这段代码中,当我第一次点击注释上的按钮 ([self presentModalViewController:secondV animated:YES];) 时,第二个视图出现但 UITextView 的文本没有改变,当我回到 FirstView 时([self dismissModalViewControllerAnimated:YES];) 然后再次点击按钮再次切换到 secondView 的 UITextView 文字变化.....

对不起,长线程和我的英语不好!

谢谢堆栈!

4

2 回答 2

0

您的代码中有两个 UITextView:myTextView 和 postitTextView。在 IB 中,您的 UIView 中有正确的吗?

于 2009-12-09T17:44:01.840 回答
0

我忘记设置myTextView@property

@property(nonatomic, retain)UITextView *myTextView;

我忘记@syntesize在实现中插入:

@syntesize myTextView;
于 2009-12-09T17:52:19.703 回答