ios tableview文本编辑滚动时丢失的数据

时间:2016-02-24 13:16:19

标签: ios objective-c iphone xcode uitableview

我正在使用UIview并添加了tableview。api发送数据以显示tableiveiw中的文本字段。我可以使用编码显示单元格中的文本字段数据bt问题是当我滚动tableview时文本值丢失。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return subIncidentArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *cellIdentifier = @"cellapi";
    UITableViewCell *incidentCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    NSInteger row = [indexPath row];
    NSDictionary *dic = [subIncidentArray objectAtIndex:row];

    if (incidentCell == nil)
        incidentCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

    if ([[dic objectForKey:@"TemplateType"] isEqual:@1]) {
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 40, 300, 30)];
        textField.delegate = self;
        textField.tag = 1;
        textField.text = self.contentOfTextField;
        [incidentCell addSubview:textField];
        textField.borderStyle = UITextBorderStyleRoundedRect;
        textField.textColor = [UIColor grayColor];

        if ([dic objectForKey:@"TextValue"] ==[NSNull null])
             textField.text = [dic objectForKey:@""];
        else
             textField.text = [dic objectForKey:@"TextValue"];
    }

    return incidentCell;
}

3 个答案:

答案 0 :(得分:0)

尝试这样,它可能会起作用

  UITableViewCell *incidentCell = [[UITableViewCell alloc]init];

答案 1 :(得分:0)

public class Circle extends GeometricObject
{

    public double radius;

    public Circle (double radius) 
    {
        this.radius = radius;
    }

    public double getRadius()
    {
        return radius;
    }

    public double getArea()
    {
        return radius * Math.PI;
    }
}

试试这个可行。

答案 2 :(得分:0)

我遇到了同样的错误,首先要确保subIncidentArray中的cellForRowAtIndexPath不为空。 尝试在此方法中重新初始化此数组的数据

相关问题