在我的筆尖,我有一個UITextView
組件。UITextView成員變量始終爲零在我的UIViewController
在我UIViewController
我有一個UITextView
成員字段和我用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作爲textview?發佈更多代碼。 – samxli
你在哪裏調用'setText:'?你確定視圖已經從NIB加載? – pmdj
請不要重複發佈。請參閱:[我如何得到我未答覆的問題的關注?](http://meta.stackexchange.com/questions/7046/how-do-i-get-attention-for-my-old-unanswered-questions) –