iOS 8 - 滚动UITableview时,UITextField中的文本消失

时间:2014-10-24 10:55:11

标签: uitableview ios8

我有一个加号按钮,点击后会在UITableview中创建两行标题,每行都有一个UILabel和一个UITextfield。此过程继续,您单击加号按钮的次数。我的问题是,如果我在UITextfield中输入一些文本并向上或向下滚动表格视图,它的文本就会消失。

这是我的代码,但是没有代码可以保存UITextfield数据(因为我不知道我想做什么)。

- (IBAction)addCycles:(id)sender {
    [sectionsArray addObject:[NSString stringWithFormat:@"Cycle %d",[sectionsArray count]+1]];
    [rowsInSectionArray addObject:[NSString stringWithFormat:@"Row %d",[rowsInSectionArray count]]];
    [tablesForCycles reloadData];
}

#pragma mark Table View data source and delegate

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [sectionsArray count];
}

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

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return [sectionsArray objectAtIndex:section];
}

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

    NSString *cellIdentifier=@"Cell";
    UITableViewCell *cell;
    cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (!cell) {
            cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
            chemoDateLabel=[[UILabel alloc]initWithFrame:CGRectMake(8, 9, 100, 40)];
            cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"background.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
    }
    [chemoDateLabel setFont:[UIFont systemFontOfSize:9]];
    NSArray *cellLabelsText=[NSArray arrayWithObjects:@"Chemo Date",@"Chemo Agent", nil];
    cell.textLabel.text=[cellLabelsText objectAtIndex:indexPath.row];
    if (indexPath.row==0) {
        chemoDateTF=[[UITextField alloc]initWithFrame:CGRectMake(150, 11, 160, 25)];
        chemoDateTF.delegate=self;
        [chemoDateTF setBorderStyle:UITextBorderStyleRoundedRect];
        [cell addSubview:chemoDateTF];
        cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"background.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
        chemoDateTF.inputView=datePickerForCell;
    }else if (indexPath.row==1){
        chemoAgentTF=[[UITextField alloc]initWithFrame:CGRectMake(150, 11, 160, 25)];
        chemoAgentTF.delegate=self;
        [chemoAgentTF setBorderStyle:UITextBorderStyleRoundedRect];
        [cell addSubview:chemoAgentTF];
        cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"background.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
    }
    return cell;
}

0 个答案:

没有答案