1

こんにちは私は問題があります。私は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に再度切り替えます。

長いスレッドと私の悪い英語でごめんなさい!

スタックありがとう!

4

2 に答える 2

0

コードには、myTextView と postitTextView の 2 つの UITextView があります。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 に答える