0

如果我使用此代码,则UITextField不会调用其delegate方法。在这段代码中,我UITextFieldUITableView.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{  
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

        if (cell == nil)
        {          
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
            cell.accessoryType = UITableViewCellAccessoryNone;

            if (indexPath.row!=7) 
            {

            [cell.textLabel setTextColor:[UIColor blackColor]];
            [cell.textLabel setTextColor:[UIColor blackColor]];

            //Creating Lable

            UILabel *lblText= [[UILabel alloc]  initWithFrame:CGRectMake(53, 30, 150, 35)];


            [lblText setFont:[UIFont boldSystemFontOfSize:15.0]];
            lblText.backgroundColor=[UIColor clearColor];

            lblText.textColor=[UIColor blackColor];


            lblText.text = [labelArray objectAtIndex:indexPath.row];



            //creating a the textField 

            UITextField *txtField = [[UITextField alloc] init];
            [txtField setFrame:CGRectMake(50, 56, 220, 31)];

            [txtField setBackgroundColor:[UIColor whiteColor]];


            [txtField setBorderStyle:UITextBorderStyleRoundedRect];
            txtField.delegate=self;
            [txtField setFont:[UIFont systemFontOfSize:14.0]];
            txtField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
                txtField.userInteractionEnabled=YES;
                txtField.enabled=YES;                


            if (indexPath.row==2)
            {
                txtField.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
            }
            else if(indexPath.row==3)
            {
                txtField.keyboardType=UIKeyboardTypeEmailAddress;

            }else
                {

                    txtField.keyboardType=UIKeyboardTypeDefault;

                }

                if (indexPath.row==6 ||indexPath.row==5) 
                {
                    [txtField setSecureTextEntry:YES];
                }

            txtField.tag=indexPath.row;
            [cell addSubview:txtField];

            [cell addSubview:lblText];  
        } 
    }

    return cell;
}
4

1 回答 1

0

我刚刚遇到了同样的问题。由于我在任何地方都找不到关于 stackoverflow 的答案,所以这对我有用:

除了 1)为从情节提要到 UITableViewController 代码的字段制作出口,以及 2)在 UITableViewController 代码中声明,

我不得不

3) 也通过情节提要连接代理出口:a) 转到情节提要并单击有问题的 UITextField,b) 转到该 UITextField 的 Connections Inspector 面板,然后 ctl+将委托加号拖到 UITableViewController 上UITextField 存在于情节提要中。(我拖到最左边故事板大纲中的 UITableViewController )

之后,我的 UITableViewController 触发了所有 UITextFieldDelegate 方法就好了。

于 2014-03-28T21:29:08.163 回答