gpt4 book ai didi

ios - 将文本移动到 UITableViewCell 中的下一个文本字段

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:27:49 24 4
gpt4 key购买 nike

我有一个 UITableView 和多个 UITableViewCell

每个单元格都有一个 UITextFiled

现在我要将文本添加到第 1 行文本文件中。现在我想在文本范围达到屏幕宽度时将文本移动到第 2 行文本文件。

编辑:

Textfiled 委托(delegate)方法

 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
CGFloat textWidth = [textField.text sizeWithAttributes:@{NSFontAttributeName : textField.font}].width;
CGFloat frameWidth = textField.frame.size.width - 11;

if(textWidth > frameWidth) {

//text reaches to screen width.
[textField resignFirstResponder];

MemoTableViewCell *nextCell = [_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:(textField.tag+1) inSection:0]];
[nextCell.noteTextField becomeFirstResponder];

return NO;
}

return YES;

}

表格 View 方法:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 20;
}


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

MemoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

if (cell == nil) {
cell = [[MemoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}

cell.noteTextField.delegate = self;
cell.noteTextField.tag = indexPath.row;

return cell;
}

现在我想在上面的方法返回 NO 时移动文本。

抱歉我的英语不好。我希望你能理解我的问题,如果不明白就问我。

请帮帮我

编辑

上面的代码工作正常,但有时它会在下面的行崩溃

CGFloat textWidth = [textField.text sizeWithAttributes:@{NSFontAttributeName : textField.font}].width;

Warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available.

最佳答案

试试下面的代码,可能会有帮助:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {


CGFloat textWidth = [textfield.text sizeWithAttributes:@{NSFontAttributeName : textfield.font}].width;
CGFloat frameWidth = textfield.frame.size.width;

if(textWidth > frameWidth) {

//text reaches to screen width.
[textfield resignFirstResponder];

/*
//Get next TextField and Make it first responder
[cell.YourNextTextField becomeFirstResponder];
*/

return NO;
}

return YES;
}

关于ios - 将文本移动到 UITableViewCell 中的下一个文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40151972/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com