こんにちは私は問題があります。私は2つのviewcontrollerを持っています。最初に、mapViewの注釈のボタンをタップする関数「calloutAccessoryControlTapped」を実装するmapViewがあります。2番目には、UITextViewだけがあります。注釈のボタンがクリックされたら、2番目のコントローラーの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];
//これからセカンドビューに切り替えます[selfpresentModalViewController:secondVアニメーション:YES]; @終わり
(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;}
このコードでは、2番目のビューが最初に表示されたときに注釈のボタン([self presentModalViewController:secondVアニメーション:YES];)をタップすると、UITextViewのテキストは変更されません。FirstViewに戻ったとき([self dismissModalViewControllerAnimated:YES];)次に、ボタンをもう一度タップして、UITextView変更のテキストをsecondViewに再度切り替えます。
長いスレッドと私の悪い英語でごめんなさい!
スタックありがとう!