UITextField 中的文本在 UITableView 中消失,如果滚动 UITableView

发布于 2025-01-08 16:10:13 字数 853 浏览 2 评论 0原文

我在 UITableView 上遇到问题,如果我将 UITextField 放在 UITableView 中,则滚动 UITableView 时,UITextField 中输入的文本将被删除。任何将数据保存在 UITextField 中的方法。

我使用了下面的代码

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cell_ID=@"CELL_ID";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cell_ID];

    if(cell==nil)
    {
        NSArray *nib=[[NSBundle mainBundle] loadNibNamed:@"TableViewCellView" owner:self options:nil];
        if([nib count]>0)
        {
            cell=[nib objectAtIndex:0];
        }
        else
        {
            NSLog(@"Failed to load nib");
        }
    }

    UITextField *txt1=(UITextField*)[cell viewWithTag:1];//not needed

    return cell;

}

我使用 xib 设计了 ​​UITableViewCell

提前致谢

I have a problem on UITableView,If i placed UITextField in UITableView,the entered text in UITextField is deleted,if scroll the UITableView. Any way to keep that data in UITextField.

I have used the below code

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cell_ID=@"CELL_ID";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cell_ID];

    if(cell==nil)
    {
        NSArray *nib=[[NSBundle mainBundle] loadNibNamed:@"TableViewCellView" owner:self options:nil];
        if([nib count]>0)
        {
            cell=[nib objectAtIndex:0];
        }
        else
        {
            NSLog(@"Failed to load nib");
        }
    }

    UITextField *txt1=(UITextField*)[cell viewWithTag:1];//not needed

    return cell;

}

I have designed the UITableViewCell using the xib

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟若柳尘 2025-01-15 16:10:13

取消选中表视图 xib 文件中的自动调整子视图大小。
并将可编辑的否设置为文本字段

Un check the auto resize subvies in table view xib file.
and set editable no to the textfiled

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文