繁体   English   中英

从UItableViewcell选择中将文本传递到UItextfield

[英]Pass text to UItextfield from UItableViewcell selection

我试图将文本从UITableViewCell选择传递给UITextField

我这样设置了didSelectRowAtIndex

#pragma mark -- select row
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];

    NSLog(@"%@", selectedCell.textLabel.text);// shows correct values

    currentSelected.text = selectedCell.textLabel.text; // currentSelected is defined below


    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

那是我的表视图选择,如您所见,我正在尝试将文本传递给currentSelected UITextField但是什么也没有发生。

这就是我设置当前选择的方式

#pragma mark - TextField delegates
- (void)textFieldDidBeginEditing:(UITextField *)textField {

    currentSelected = textField;

}
#pragma mark - TextField delegates
- (void)textFieldDidBeginEditing:(UITextField *)textField {

    currentSelected = textField;

}

用以下方法替换,并确保清除了文本字段委托

#pragma mark - TextField delegates
- (void)textFieldDidEndEditing:(UITextField *)textField {

    currentSelected.text = textField.text;

}

将字符串保存到视图控制器的属性中,而不是文本字段中。

然后,将文本放在属性中后,可以根据需要在文本字段中显示它。

我的猜测是在didSelectRowAtIndexPath中,currentSelected为nil。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM