2011-07-02 28 views
0

在我的筆尖,我有一個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 
+1

您是否使用IBOutlet作爲textview?發佈更多代碼。 – samxli

+0

你在哪裏調用'setText:'?你確定視圖已經從NIB加載? – pmdj

+1

請不要重複發佈。請參閱:[我如何得到我未答覆的問題的關注?](http://meta.stackexchange.com/questions/7046/how-do-i-get-attention-for-my-old-unanswered-questions) –

回答

0

保存筆尖文件連接插座後,建設項目和運行,如果它連接

+0

我做到了,但沒有奏效。您能否澄清「連接插座」中涉及的確切步驟? – user605957

+0

我總是這樣做在IB:1.在文件的所有者上單擊鼠標右鍵。 2.從textView出口拖到UITextView控件。它應該看起來像製作連接部分的第一張圖片:[鏈接](http://disanji.net/iOS_Doc/#documentation/iPhone/Conceptual/iPhone101/Articles/05_ConfiguringView.html)。我想你從上面的描述中做了正確的... – alhcr

+0

有沒有一種方法可以查看實際的XML文件並查看是否有錯誤? – user605957

0

我看不到AGERE您所呼叫的setText它應該工作,但是我認爲你嘗試在初始化器中完成它。在使用XIB或loadView的情況下,如果以編程方式製作GUI,或者使用其他viewWill/viewDid ...方法,GUI代碼不應該在viewDidLoad之前完成。

原因是因爲視圖在實際需要之前未加載,所以稱爲延遲加載。你應該谷歌瞭解更多信息。