问题 setText UITextView

发布于 2024-08-13 21:03:00 字数 1593 浏览 2 评论 0原文

嗨,我有一个问题。我有2个视图控制器,第一个是一个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];

//从这个视图切换到第二个视图 [自我呈现ModalViewController:第二个V动画:是]; @end

(SecondViewController)

标头

@interface SecondViewController{ 
IBOutlet UITextView *myTextView;
}

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

实现

@implementation SecondViewController

- (IBAction)backToMAp{

//返回第一个视图; [selfmissModalViewControllerAnimated:YES];}

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

在此代码中,当我点击注释上的按钮 ([selfpresentModalViewController:secondVanimated:YES];) 时,第二个视图第一次显示,但 UITextView 的文本不会更改,当我回到 FirstView ([self dismissModalViewControllerAnimated:YES];),然后再次点击按钮再次切换到 secondaryView,UITextView 的文本发生变化......

抱歉,长线程和我的英语不好!

谢谢堆栈!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

年华零落成诗 2024-08-20 21:03:00

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

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

蓝眸 2024-08-20 21:03:00

我忘记将 myTextView 设置为 @property

@property(nonatomic, retain)UITextView *myTextView;

并且忘记在实现中插入 @syntesize

@syntesize myTextView;

I forget to set myTextView as @property:

@property(nonatomic, retain)UITextView *myTextView;

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

@syntesize myTextView;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文