我有一個iOS應用程序,我最近更新了它來處理UIAlertView/SubView問題,該問題導致文本框呈現爲清晰或白色(或根本不渲染,不知道哪個) 。無論如何,這是一個相對簡單的問題,因爲我對Obj-C很陌生,但是如何從應用中的另一個調用中獲取新文本框的值?在iOS應用程序中從UIAlertView文本框中檢索值
這裏是我的UIAlertView中:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Password"
message:@"Enter your Password\n\n\n"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Login", nil];
alert.frame = CGRectMake(0, 30, 300, 260);
它曾經被存儲爲一個的UITextField,然後加入到UIAlertView中作爲一個子視圖:
psswdField = [[UITextField alloc] initWithFrame:CGRectMake(32.0, 65.0, 220.0, 25.0)];
psswdField.placeholder = @"Password";
psswdField.secureTextEntry = YES;
psswdField.delegate = self;
psswdField.tag = 1;
[psswdField becomeFirstResponder];
[alert addSubview:psswdField];
[alert show];
[alert release];
這一切現在註釋掉,並相反,我把它改寫爲:
alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
這是我如何檢索值:
[psswdField resignFirstResponder];
[psswdField removeFromSuperview];
activBkgrndView.hidden = NO;
[activInd startAnimating];
[psswdField resignFirstResponder];
[self performSelectorInBackground:@selector(loadData:) withObject:psswdField.text];
現在我有點困惑,我如何從該文本框的值發送到loadData。
對,有道理。正如你在我的問題中看到的,我已經在做第一部分。我想我需要幫助的是如何實際檢索文本字段的示例。再說一遍,我是iOS新手,而且我更像是一個C#人員,而不是obj-c。我可以解決它,但我還不是很熟練。 – optionsix
我真正需要幫助的是:我假設alert.alertViewStyle = UIAlertViewStyleSecureTextInput部分創建一個輸入文本框。方法didDismissWithButtonIndex在按下按鈕後調用該操作來對該文本框執行某些操作。之後是我朦朧的地方,我如何從委託方法中的文本框中獲取數據? – optionsix
我剛剛添加了委託方法的示例實現,當您關閉對話框時,該方法會將文本字段中的值打印到控制檯。所以你可以看看你如何看待文本字段。 – Gavin