【问题标题】:UITableview Cell scrolling time textfield data is disappearing after update textUITableview Cell滚动时间文本字段数据在更新文本后消失
【发布时间】:2018-05-27 00:52:16
【问题描述】:

我正在使用 UITableview 单元格列出一组问题,2 个文本字段用于分数 1 和分数 2 我输入了分数和总分显示在标签上之后,当我滚动时,输入的数据在 UITableview 上消失了。一些请帮我解决这个问题,并在视图上添加这些文本字段和标签,这个视图是 cell.contentview 的子视图

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
else{
    for (UIView* view in cell.contentView.subviews) {
        if ([view isKindOfClass:[UIView class]]) {
            [view removeFromSuperview];
        }
    }
}

文本字段添加为

UIView * vwbackground = [[UIView alloc] init];
[vwbackground setFrame: CGRectMake(5.0, 5.0, [UIScreen mainScreen].bounds.size.width-10, 90)];
vwbackground.backgroundColor = [UIColor whiteColor];
[cell.contentView addSubview:vwbackground];

self.txtfldInPut1.clearButtonMode = UITextFieldViewModeWhileEditing;
self.txtfldInPut1.autocorrectionType = UITextAutocorrectionTypeNo;
self.txtfldInPut1.inputAccessoryView = numberToolbar;
[vwbackground addSubview:self.txtfldInPut1];

【问题讨论】:

    标签: ios xcode uitableview uiscrollview uitextfield


    【解决方案1】:

    这是因为表格单元格中的数据在滚动时会根据列表项不断变化。这是表格视图中单元格的一个特性。 您需要做的是在输入您的分数时将该值更新为您最初在列表中显示数据的数组/字典(无论您采用什么)。
    希望对你有帮助:)

    【讨论】:

    • 我将该数据转换为一个字符串,如果重新加载该数据,我设置一个布尔值,该数据也正在消失
    • 只是为了澄清主要数据来自api,即它是jason格式
    • 是的,来自 api 的主要数据和用户添加分数 1 和 2 并且总和在滚动后也显示它正在消失
    • 就我不理解您的问题而言,请执行这些操作 .. 1). 将第一次来自 api 的数据保存到您的本地字典中。 2)。从您使用的本地词典中的列表视图中显示列表 3) 。当用户输入分数时,然后用分数更新字典。如果你这样做了,那么即使向上滚动,数据也会按照你想要的方式更新分数。
    • 仅用于前。 {“输入”:[{“问题”:“any1”,“分数”:“0”},{“问题”:“any2”,“分数”:“0”},{“问题”:“any3” , "scores": "0" } ] } 你的本地字典应该看起来像这样,并根据输入的分数更新分数
    猜你喜欢
    • 1970-01-01
    • 2010-10-10
    • 1970-01-01
    • 1970-01-01
    • 2019-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多