自定义单元格

时间:2017-01-13 10:42:24

标签: ios objective-c uitableview uitextfield cell

我在桌面视图上有自定义单元格。 Cell有一个文本字段。例如,如果我有4个单元格,每个单元格都有textfield。我可以点击三个文本字段,相关的文本字段开始编辑。但对于其中一个文本字段,当我点击它 - 文本字段确实开始编辑没有被调用。这是我的方法

  -(void)textFieldDidBeginEditing:(UITextField *)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)setEditing:(BOOL)editing animated:(BOOL)animated {

    [super setEditing:editing animated:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(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)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    if (selected) {`selectHilightCount++;
        self.accountNameTxtField.enabled = NO;
    } else {
        self.accountNameTxtField.enabled = YES;
    }`
}

2 个答案:

答案 0 :(得分:0)

请设置代表。 像:

cell.txtFld.delegate = self;

希望它会让你感动。谢谢

答案 1 :(得分:0)

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
 CustomCell *cell = (CustomCell *)[self.tableView viewWithTag:textField.tag];
 NSIndexPath *indexPath = [self.tableView indexPathForCell:cell]; 
 NSLog@("indexPath ===%ld", indexPath.row)
 // You can make logic as you want
}
相关问题