私のペン先には、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
テキストビューにIBOutletを使用しましたか?もっとコードを投稿してください。 – samxli
あなたは 'setText:'をどこで呼び出していますか?ビューが既にNIBからロードされていますか? – pmdj
ダブルポストしないでください。参照:[未回答の質問にはどのように注意を払うのですか?](http://meta.stackexchange.com/questions/7046/how-do-i-get-attention-for-my-old-unanswered-questions) –