gpt4 book ai didi

iphone - 单击按钮时如何获取 UITextField 值

转载 作者:行者123 更新时间:2023-11-28 20:44:26 25 4
gpt4 key购买 nike

我的看法是:

enter image description here

和这些实现:

- (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;
}

当用户单击“登录”按钮而没有点击“完成”以关闭键盘时,它不会保存字段值。我该如何巧妙地解决这个问题?

最佳答案

两种选择:

保留对两个文本字段的引用,并在“完成”按钮的操作方法中提取它们的 text 值。

或者,注册 UITextFieldTextDidChangeNotification 并在输入发生时捕获它。

关于iphone - 单击按钮时如何获取 UITextField 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7034433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com