簡體   English   中英

如何在按鈕當前標題上設置驗證

[英]how to set validation on button current title

嗨,我是 iphone 開發新手,我的任務是開發 uibutton 和選擇器相關應用程序。

我必須開發一個具有按鈕 1 uipicker 視圖的視圖。 當我當時運行應用程序時,按鈕的標題為空白。 如果用戶當時直接單擊提交按鈕,用戶將收到錯誤消息。

但是我會收到錯誤消息,並且我的以下代碼無法正常工作,它正在提交表單而不檢查按鈕文本驗證。

以下是我的代碼:

if ([btnPicker.currentTitle isEqualToString:@" "]) {

     UIAlertView *alertPicker = [[UIAlertView alloc] initWithTitle:@"Required" message:@"Please,Select Month & Date." delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No",nil];
     [alertPicker show];
     NSLog(@"%@", alertPicker);
     [alertPicker release];
 }

實際上空字符串是空字符串@""不是空格@" " 你必須像這樣測試一個空字符串,

[btnPicker.currentTitle isEqualToString:@""];
[btnPicker.currentTitle isEqualToString:@""];

或者

if ([btnPicker.currentTitle length]==0)

不應該是[btnPicker.currentTitle isEqualToString:@""]嗎? 沒有空格的字符串?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM