2012-06-06 52 views
0

我希望當用戶在textfiled中輸入錯誤值時,它會顯示警報,並且會使textfield emty和按鈕標題爲空。在我的代碼文本框中,沒有得到空值UIButton的標題沒有設置爲空或iPhone中的空白

下面

是我的代碼

 if (monthText>totalnumber) { 
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Value Must Be Less than total number of dogs " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 

    NSString *titleMonth [email protected]"0"; 
    [cereniaButton setTitle:@"" forState:UIControlStateNormal]; 






    [email protected]""; 


    } 


int year=12; 
int monthButtonTitle=monthText*year; 
NSString *titleMonth =[NSString stringWithFormat:@"%d",monthButtonTitle]; 
[cereniaButton setTitle:titleMonth forState:UIControlStateNormal]; 
+0

你可以嘗試指派 「」 用的NSString * titleMonth = @」「; – CarlJ

+0

也沒有顯示 – james

+0

你可以發佈NSLog(@「%@」,cereniaButton); – CarlJ

回答

0

要重設冠軍,但之後你的標題會ripopolate後。

嘗試

if (monthText>totalnumber) { 
    //...yourcode... 

    return; 
} 

讓我知道

0

,如果你直接給喜歡

會發生什麼[BTN的setTitle:@ 「」 forState:UIControlStateNormal]。

+0

其不顯示空白它顯示以前的值 – james

+0

看到我的編輯代碼 – james

+0

然後可能是舊值必須存儲在一些字符串和執行上面的行時,可能會有一些代碼會放置它字符串作爲按鈕的標題。 – Dhruv

0

寫這行標題設置按鈕

[self.view setNeedsDisplay]; 
0

可能是u的缺失與文件所有者連接按鈕,試試這個:

  1. 聲明IBOutlet中,以按鈕.h文件中,按鈕這是由xib創建的。
  2. @synthesize btn in .m
  3. 將按鈕(btn)連接到xib中的文件所有者。並使用該委託:

- (空)textFieldDidEndEditing:(*的UITextField)文本框

int txtValue = [textField.text intValue]; 
if(txtValue < 10) 


    btn.titleLabel.text = [NSString stringWithFormat:@"%d",txtValue]; 
     else 
     { 
      btn.titleLabel.text = [NSString stringWithFormat:@""]; 
     } 
    } 
    - (BOOL)textFieldShouldReturn: (UITextField *)textField 
    { 
     [textField resignFirstResponder]; 
     return YES; 
    }