2014-02-13 28 views
-1

用戶已經輸入的最小字符的UITextField後我有一個iPhone應用程序,其中我有一個的UITextField其最大字符長度I SET使用委託方法:需要啓用一個UIButton使用委託方法在IOS

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 

然而,我現在意識到,我還需要啓用UIButton *myButton,當用戶在同一個UITextField中輸入至少一個字符時,我就擁有這個UIButton *myButton。我如何實現這一點?

這裏是我的相關代碼,我在我的委託方法目前所面對的:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { 
    NSUInteger newLength = [textField.text length] + [string length] - range.length; 
    return (newLength > 45) ? NO : YES; 
} 

在此先感謝所有誰答覆。

回答

4

開始出具有禁用的UIButton然後啓用按鈕,如果文本字段的文本長度大於0

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { 
    NSUInteger newLength = [textField.text length] + [string length] - range.length; 

    // Enable/disable the button depending on the length of the text 
    if (newLength > 0) button.enabled = YES; 
    else button.enabled = NO; 

    return (newLength > 45) ? NO : YES; 
}