時,我有這樣的觀點:如何獲得的UITextField值按鈕被點擊
和這些實現:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableLogin dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if ([indexPath section] == 0) {
UITextField *textfield = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 165, 30)];
textfield.adjustsFontSizeToFitWidth = YES;
textfield.textColor = [UIColor blackColor];
textfield.backgroundColor = [UIColor whiteColor];
textfield.autocorrectionType = UITextAutocorrectionTypeNo;
textfield.autocapitalizationType = UITextAutocapitalizationTypeNone;
textfield.textAlignment = UITextAlignmentLeft;
textfield.clearButtonMode = UITextFieldViewModeNever;
textfield.delegate = self;
if ([indexPath row] == 0) {
textfield.tag = 0;
textfield.placeholder = @"your username";
textfield.keyboardType = UIKeyboardTypeDefault;
textfield.returnKeyType = UIReturnKeyNext;
}
else {
textfield.tag = 1;
textfield.placeholder = @"required";
textfield.keyboardType = UIKeyboardTypeDefault;
textfield.returnKeyType = UIReturnKeyDone;
textfield.secureTextEntry = YES;
}
[textfield setEnabled:YES];
[cell addSubview:textfield];
[textfield release];
}
}
if ([indexPath section] == 0) {
if ([indexPath row] == 0) {
cell.textLabel.text = @"Email";
}
else {
cell.textLabel.text = @"Password";
}
}
return cell;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
switch (textField.tag) {
case 0:
self.username = textField.text;
break;
case 1:
self.password = textField.text;
break;
}
return true;
}
當無龍頭的用戶點擊登錄按鈕「完成」了近鍵盤不保存字段值。我怎樣才能解決這個問題?
什麼是'UITextFieldTextDidChangeNotification'?我找不到任何東西。 –
這是爲UITextField定義的通知名稱。你會註冊這樣說:'[NSNotificationCenter defaultCenter]的addObserver:自我選擇:@選擇(textFieldDidChange :)名稱:UITextFieldTextDidChangeNotification對象:文本字段]' –
文檔* *是奇怪稀疏。第22本* PDF的*列出所有的類所支持的通知:http://developer.apple.com/library/ios/documentation/uikit/reference/UITextField_Class/UITextField_Class.pdf –