Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 关闭文本字段上的键盘-自定义表格单元格_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 关闭文本字段上的键盘-自定义表格单元格

Ios 关闭文本字段上的键盘-自定义表格单元格,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个自定义单元格,在自定义单元格中,我有一个文本字段,用户可以在其中更改值。不管我怎么做,当用户输入一些值时,我都无法关闭键盘。它不会影响下面显示的任何委托方法 CheckOutTableViewCell.m #import "CheckOutTableViewCell.h" @implementation CheckOutTableViewCell @synthesize productName; @synthesize productPrice; @synthesize product

我有一个自定义单元格,在自定义单元格中,我有一个文本字段,用户可以在其中更改值。不管我怎么做,当用户输入一些值时,我都无法关闭键盘。它不会影响下面显示的任何委托方法

CheckOutTableViewCell.m

#import "CheckOutTableViewCell.h"

@implementation CheckOutTableViewCell
@synthesize productName;
@synthesize productPrice;
@synthesize productOrderNumberTF;

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(id) init;
{
    self = [super init];
    if (!self) return nil;
    productOrderNumberTF.delegate = (id)self;
    return self;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    // enter closes the keyboard
    if ([string isEqualToString:@"\n"])
    {
        [textField resignFirstResponder];
        return NO;
    }
    return YES;
}

- (void) textFieldDidEndEditing:(UITextField *)textField {
    NSLog(@"%@", textField.text);
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

// dismiss keyboard when user clicks on anywhere on the UI
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.productOrderNumberTF resignFirstResponder];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *cellIdentifier = @"cell";
        CheckOutTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (cell == nil)
        {
            cell = [[CheckOutTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
            cell.productOrderNumberTF.delegate = (id)self;
        }
   return cell
}
CheckOutTableViewController.m

#import "CheckOutTableViewCell.h"

@implementation CheckOutTableViewCell
@synthesize productName;
@synthesize productPrice;
@synthesize productOrderNumberTF;

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(id) init;
{
    self = [super init];
    if (!self) return nil;
    productOrderNumberTF.delegate = (id)self;
    return self;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    // enter closes the keyboard
    if ([string isEqualToString:@"\n"])
    {
        [textField resignFirstResponder];
        return NO;
    }
    return YES;
}

- (void) textFieldDidEndEditing:(UITextField *)textField {
    NSLog(@"%@", textField.text);
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

// dismiss keyboard when user clicks on anywhere on the UI
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.productOrderNumberTF resignFirstResponder];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *cellIdentifier = @"cell";
        CheckOutTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (cell == nil)
        {
            cell = [[CheckOutTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
            cell.productOrderNumberTF.delegate = (id)self;
        }
   return cell
}
ViewController的屏幕截图


您的
委托
方法未调用,因为您的
文本字段委托
值未赋值

awakeFromNib

- (void)awakeFromNib {
    [super awakeFromNib];
    productOrderNumberTF.delegate = self;
}
nib加载基础结构向从nib存档重新创建的每个对象发送一条消息,但只有在存档中的所有对象都已加载并初始化之后。当一个对象收到awakeFromNib消息时,它保证已经建立了所有的出口和操作连接


删除cell.productOrderNumberTF.delegate=(id)self来自您的
签出TableViewController.m
类。它是在
TableCell.m
还是
TableViewController.m
中?