我在表格 View 上有自定义单元格。单元格有一个文本字段。例如,如果我有 4 个单元格,每个单元格都带有文本字段。我可以点击三个文本字段,并且相关的文本字段确实开始编辑。但是对于其中一个文本字段,当我点击它时 - 文本字段确实开始编辑并没有被调用。这是我的方法
-(void)textFieldDidBeginEditingUITextField *)textField{
NSString *SelectedIndexString = [[NSUserDefaults standardUserDefaults]
stringForKey"SelectedIndex"];
NSInteger selectionCount = [SelectedIndexString integerValue];
NSLog(@"%ld",(long)selectionCount);
if (selectionCount) {
self.accountNameTxtField.enabled = NO;
}
else{
self.accountNameTxtField.enabled = YES;
}
}
// STTableViewCell
@interface STTableViewCell () <UITextFieldDelegate>
- (void)awakeFromNib {
[super awakeFromNib];
radioBtn.alpha = 0; // Initialization code [self customBorder];
// Setting the OTP label color to the RGB blue
self.OTPLabel.textColor = [UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0];
// Set delegate to textfield
self.accountNameTxtField.delegate=self;
}
- (void)setEditingBOOL)editing animatedBOOL)animated {
[super setEditing:editing animated:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selectorselector(incomingNotification name"No Change" object:nil];
if (!editing)
{
radioBtn.alpha = 0;
isTableviewEditing=NO;
if (![self.authURL.name isEqual:accountNameTxtField.text]) {
self.accountNameTxtField.text = [self.accountNameTxtField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (accountNameTxtField.text.length >= 1)
{
// Write out the changes.
descriptionBlank = NO;
self.authURL.name = self.accountNameTxtField.text;
[self.authURL saveToKeychain];
}
else{
[accountNameTxtField resignFirstResponder];
[self.delegate cellDidTap:self];
self.accountNameTxtField.text =self.authURL.name;
descriptionBlank = YES;
}
}
accountNameTxtField.userInteractionEnabled=NO;
[accountNameTxtField resignFirstResponder];
for (CALayer *layer in accountNameTxtField.layer.sublayers) {
if ([layer.name isEqualToString"Gradient"])
{
[layer setHidden:YES];
break;
}
}
progressView.alpha=1.0;
OTPLabel.alpha=1.0;
}
else
{
radioBtn.alpha = 1;
isTableviewEditing=YES;
for (CALayer *layer in accountNameTxtField.layer.sublayers) {
if ([layer.name isEqualToString"Gradient"])
{
[layer setHidden:NO];
break;
}
}
OTPLabel.alpha=0.0;
progressView.alpha=0.0;
accountNameTxtField.userInteractionEnabled=YES;
}
}
- (void)setSelectedBOOL)selected animatedBOOL)animated
{
[super setSelected:selected animated:animated];
if (selected) {`selectHilightCount++;
self.accountNameTxtField.enabled = NO;
} else {
self.accountNameTxtField.enabled = YES;
}`
}
Best Answer-推荐答案 strong>
请设置委托(delegate)。
喜欢:
cell.txtFld.delegate = self;
希望对你有帮助。谢谢
关于ios - 没有在自定义单元格上调用文本字段确实开始编辑,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/41632707/
|