2016-07-29 39 views
0

我有一個輔助類看起來是這樣的:傳遞一個UITextFieldDelegate到的UIViewController輔助類

(我們稱這個GUI.H & GUI.M文件)

(DOT .h文件。 )

- (CGGroup)addLabelTextField:(UIViewController*)vc deligate:(id<UITextFieldDelegate>)deligate textField:(UITextField*)textField; 

(DOT ... M FILE)

- (CGGroup)addLabelTextField:(UIViewController*)vc deligate:(id<UITextFieldDelegate>)deligate textField:(UITextField*)textField 
{ 

    // Blah, Blah Blah Blah Set Up & Configure Label & Textfield... 10 lines 

    // DONE Allocating & Configuring OK 

    // Last 3 Lines -- this is where the Deligate gets SET and the problems 
    textField.delegate = deligate; // <- this is what is NOT happening 
    [vc.self.view addSubview:textField]; // this adds TextField to passed in UIViewController 
    return(cgTmp); // nothing to see here just a typedef of CGRect's 

} 

我通過視圖控制器,文本框的指針,textFieldDeligate並設置它們programmically(NO XIB就是那麼過)

的Alloc,設置,抽搐,就像你可以創建/配置一個文本框或標籤在你要使用它的viewcontroller中,除了傳遞helper類設置所有東西。所以添加字段是一個電話,並不是所有通常的配置...

問題: 一切似乎工作正常,除了TextFieldDeligate函數沒有被調用(鏗鏘 - 沒有警告,什麼都沒有.. 。)

如果我提出這個相同的代碼,返回到調用類(UIViewController的) 突然,代表們獲取調用,沒有問題,在所有...

另一個問題:一旦testfield設置,你不能改變東西,IE .. SecureText = TRUE變爲FALSE ....什麼也沒有發生,當這段代碼移回到調用viewController時,突然間ything像宣傳的那樣....

我懷疑的東西做的「UITextFieldDeligate」被傳遞的方式,但正如我所說,鐺不給任何警告... ... NONE

當然,UIViewController的設置是爲了支持 和聲明的屬性... (如果我把這些東西放回到類中(UIViewController)(沒有一個單獨的類來設置這些字段)它工作正常...

該方法被調用:

SomeUIViewController.M(這是我們稱之爲GUI.H & M的定義的功能)

[self.gui addTextField:self textField:self.passField deligate:self.passField.delegate]; 

AND YES沒有爲一個的UITextField屬性和類具有協議聲明

SomeUIViewController.H

@interface SomeUIViewController : UIViewController <UITextFieldDelegate>{ 

} 

@property (nonatomic, strong) GuiUtils *gui; 
@property (nonatomic, strong) UITextField *userField; 
@property (nonatomic, strong) UITextField *passField; 
@property (nonatomic, strong) UITextField *tmpField; 

正如我所提到的B4,唯一plroblem我experi encing是在UIViewController(與這個UITextField有關)的deligate方法沒有被調用...

(但我認爲這可能是簡單的事情,因爲我只是注意到我沒有通過作爲指針的解釋。 ..因此,它可能已經解決)提前

感謝.....

+0

你的方法調用沒有意義,請發佈正確的代碼。 –

+0

這是「方法」調用:「[self.gui addTextField:self textField:self.passField deligate:self.passField.delegate];」哪部分你不明白..?我很樂意向您解釋。 – NpC0mpl3t3

+0

確定....代表沒有被調用是固定的!我傳遞了「UITextField.delegate」的委託而不是UIViewController「self」的委託。因此,現在代理已經被調用,但仍然在設置TextField的某些屬性被添加到子視圖後出現問題...我不能改變「textField.secureTextEntry」,這是另一種工作,當完全相同的代碼被移入調用UIViewController時... – NpC0mpl3t3

回答

0

OK ....的代表沒有得到所謂的固定! 我經過 「UITextField.delegate」 的代表,而不是UIViewController的 「自我」

從委託:

[self.gui addTextField:self textField:self.passField deligate:self.passField.delegate]; 

TO:

[self.gui addTextField:self textField:self.passField deligate:self]; 
相關問題