Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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
Objective c 找不到文本字段';下一个响应者_Objective C_Ios_Keyboard_Uitextfield_Next - Fatal编程技术网

Objective c 找不到文本字段';下一个响应者

Objective c 找不到文本字段';下一个响应者,objective-c,ios,keyboard,uitextfield,next,Objective C,Ios,Keyboard,Uitextfield,Next,我正在尝试循环/导航UITextFields,我将其作为子视图添加到UITableViewCells。但是,我无法在文本字段shouldReturn:方法中获取我的下一个响应者值。有人能告诉我我的代码哪里出错了吗 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* PlaceholderCellId

我正在尝试循环/导航
UITextField
s,我将其作为子视图添加到
UITableViewCell
s。但是,我无法在
文本字段shouldReturn:
方法中获取我的
下一个响应者
值。有人能告诉我我的代码哪里出错了吗

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* PlaceholderCellIdentifier = @"PlaceholderCell";

    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:PlaceholderCellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:PlaceholderCellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
    }

    if (indexPath.row == 0) // first name
    {
        cell.textLabel.text = @"First Name:";
        UITextField *tempFirstNameField = [[UITextField alloc]initWithFrame:CGRectMake(100, (44-18)/2, 320-100, 32)];
        self.firstNameField = tempFirstNameField;
        self.firstNameField.font = [UIFont systemFontOfSize:14];
        self.firstNameField.tag = 1;
        self.firstNameField.returnKeyType = UIReturnKeyNext;
        self.firstNameField.delegate = self;
        [tempFirstNameField release];
        [cell.contentView addSubview:self.firstNameField];
    }
    else if (indexPath.row == 1) //last name
    {
        cell.textLabel.text = @"Last Name:";
        UITextField *tempLastNameField = [[UITextField alloc]initWithFrame:CGRectMake(100, (44-18)/2, 320-100, 32)];
        self.lastNameField = tempLastNameField;
        self.lastNameField.font = [UIFont systemFontOfSize:14];
        self.lastNameField.tag = 2;
        self.lastNameField.returnKeyType = UIReturnKeyNext;
        self.lastNameField.delegate = self;
        [tempLastNameField release];
        [cell.contentView addSubview:self.lastNameField];
    }

    return cell;
}

-(BOOL)textFieldShouldReturn:(UITextField*)textField;
{
    NSInteger nextTag = textField.tag + 1;
    NSLog(@"next tag %i",nextTag);
    // Try to find next responder

    UIResponder* nextResponder = [textField.superview.superview viewWithTag:nextTag];
    //This always returns me null value
    NSLog(@"next responder %@", nextResponder);
    if (nextResponder) {
        // Found next responder, so set it.
        [nextResponder becomeFirstResponder];
    } else {
        // Not found, so remove keyboard.
        [textField resignFirstResponder];
    }
    return NO; // We do not want UITextField to insert line-breaks.
}

UITableView不是数组-它可能会重新加载甚至释放任何不可见的单元格

如果您想操作创建的单元格,最好将它们全部创建,放入一个数组中,然后从数组中显示它们。也就是说,在表开始加载之前创建它们,但不在CellForRowatineXpath方法中创建。例如,可以在ViewWillDisplay中执行此操作


在这种情况下,所有对象都将保留在数组中,在您愿意之前不会释放。

UITableView不是数组-它可能会重新加载甚至释放任何不可见的单元格

如果您想操作创建的单元格,最好将它们全部创建,放入一个数组中,然后从数组中显示它们。也就是说,在表开始加载之前创建它们,但不在CellForRowatineXpath方法中创建。例如,可以在ViewWillDisplay中执行此操作


在这种情况下,数组将保留所有对象,并且在您愿意之前不会释放这些对象。

为什么需要一个表视图呢?您的字段似乎是静态的。如果内容比屏幕大,请使用简单的滚动视图。 要循环字段,您可以:

1/对导航循环中需要的所有控件使用容器视图,只需在子视图中循环
NSArray


2/最佳选择。使用
NSUInteger标记
字段设置控件获得焦点的顺序。从非零值开始,因为0是默认标记值。10,11,12,13,并在容器视图上使用
viewWithTag:
检索下一个控件。

为什么需要一个表视图,您的字段似乎是静态的。如果内容比屏幕大,请使用简单的滚动视图。 要循环字段,您可以:

1/对导航循环中需要的所有控件使用容器视图,只需在子视图中循环
NSArray

2/最佳选择。使用
NSUInteger标记
字段设置控件获得焦点的顺序。从非零值开始,因为0是默认标记值。10,11,12,13并在容器视图上使用
viewWithTag:
检索下一个控件