2011-07-02 12 views
0

私のペン先には、UITextViewコンポーネントがあります。UITextViewメンバ変数は、UIViewControllerで常にnilです。

UIViewController私はUITextViewメンバーフィールドを持っていますが、私は2つが接続されていることを確認するためにIBを使用しています(少なくとも私は "ファイル所有者"からドラッグしてIBのUITextView私のメンバー変数の選択)。

setText:でテキストを更新すると、UITextViewはまだ空白のままです。

私のコードに入ると、メンバー変数(textView)はnilとなります。

私はIBを正しく使用していないと推測しています。この変数がUITextViewグラフィック要素に接続されていることを確認するにはどうすればよいですか?ここで

はコード

// My interface looks like 

#import <UIKit/UIKit.h> 

@interface DetailsController : UIViewController 
{ 
    UITextView *textView; 
} 

@property (nonatomic, retain) IBOutlet UITextView *textView; 

@end; 


// and the implementation 

#import "DetailsController.h" 

@implementation DetailsController 

@synthesize textView; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) 
    { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)dealloc 
{ 
    [super dealloc]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

// used pressed the "Done" button 
- (IBAction)done 
{ 
    [self dismissModalViewControllerAnimated:YES]; 
} 

- (void)setDetails: (NSString *)detail withQuote:(NSString *)quote 
{ 
    NSLog(@"%@", textView); 
    [textView setText:detail]; 
} 

@end 
+1

テキストビューにIBOutletを使用しましたか?もっとコードを投稿してください。 – samxli

+0

あなたは 'setText:'をどこで呼び出していますか?ビューが既にNIBからロードされていますか? – pmdj

+1

ダブルポストしないでください。参照:[未回答の質問にはどのように注意を払うのですか?](http://meta.stackexchange.com/questions/7046/how-do-i-get-attention-for-my-old-unanswered-questions) –

答えて

0

、コンセントを接続した後のnibファイルを保存し、プロジェクトをビルドして実行、それは

+0

私はそれをしましたが、うまくいきませんでした。 「コンセントを接続する」の手順を明確にしてください。 – user605957

+0

私はこれをIBのようにいつもしています:1. File's Ownerを右クリックします。 2. textViewコンセントからUITextViewコントロールにドラッグします。 「接続」セクションの最初の図のようになります。[リンク](http://disanji.net/iOS_Doc/#documentation/iPhone/Conceptual/iPhone101/Articles/05_ConfiguringView.html)。私はあなたが上記のあなたの説明から正しいことをしたと思います... – alhcr

+0

実際のXMLファイルを見て何かが間違っているかどうかを確認する方法はありますか? – user605957

0

を接続している場合、それは動作するはずですあなたがのsetTextを呼び出しているアギア私は見ることはできませんが、私ですあなたがイニシャライザでそれをやろうとしていると思います。あなたのGUIをプログラマチックにする場合、XIBまたはloadViewを使用する場合はviewDidLoadの前にGUIコードを、または他のviewWill/viewDid ...メソッドを使用しないでください。

ビューは実際に必要とされる前に読み込まれないため、遅延読み込みと呼ばれます。詳細はGoogleにお問い合わせください。

関連する問題