问题 setText UITextView
嗨,我有一个问题。我有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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码中有两个 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?
我忘记将
myTextView
设置为@property
:并且忘记在实现中插入
@syntesize
:I forget to set
myTextView
as@property
:and i forget to insert the
@syntesize
in the implementation: