【问题标题】:UITextField into UITableViewCell auto reset when scroll down and turn back?向下滚动并返回时 UITextField 进入 UITableViewCell 自动重置?
【发布时间】:2012-05-04 12:03:40
【问题描述】:

我在UITableViewCell 中有更多UITextField,但是当我向下滚动并返回时,UITextField 是空的。有办法不自动重置吗?

这是代码:

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

    if(cell==nil){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cella"];
    }

    cell.textLabel.text = [dati objectAtIndex:indexPath.row];

    UITextField *testo = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 150, 31)];
    testo.borderStyle = UITextBorderStyleRoundedRect;
    testo.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    testo.placeholder = @"Inserisci del testo..";
    testo.delegate = self;

    cell.accessoryView = testo;

    return cell;
}

【问题讨论】:

    标签: objective-c uitableview scroll uitextfield


    【解决方案1】:

    它每次都在重新创建单元格。这就是为什么每次创建新单元格并重新初始化包含的控件时,如果 UITextField 包含文本,您可能没有设置条件,它不应该清除其文本。

    【讨论】:

    • 您必须维护一个 MutableDictionary,其中包含每个单独的 UITextField 文本的文本。下次调用该方法时,您必须检查该行的 UITextfield 的文本是否存在并相应地设置 text 属性。明白我的意思了吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多