自定义表视图单元格中的文本字段从初始文本字段中消失,并在滚动时显示在其他单元格文本字段中 [英] Textfield in Custom Table View Cell dissappears from initial textfield and appears in other cells textfield upon scrolling

查看:98
本文介绍了自定义表视图单元格中的文本字段从初始文本字段中消失,并在滚动时显示在其他单元格文本字段中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

static NSString *CellIdentifier = @"inventoryItem";


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];



if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    cell.textLabel.font = [UIFont systemFontOfSize:15];

}
 UILabel *name = (UILabel *)[cell viewWithTag:1];



NSLog(@"%@", name.text);



cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return inventoryItems.count;
}

我意识到这与dequeueReuasableCellWithIdentifier有关,但我不确定如何解决这个问题我在故事板上有文本字段然后我有一个动作将所有这些文本字段相对于它们的单元格发送到数据库。文本字段的代码在IBAction中发送数据并存储。我将添加IBAction代码:

I realize this is to do with the dequeueReuasableCellWithIdentifier but I am unsure on how to solve this. I have the textfield on storyboard and then I have an action to send all these textfields with respect to their cells to a database. The code for the textfield is in the IBAction to send the data and am storing. I will add the IBAction code :

 - (IBAction)submitCountTapped:(id)sender {


NSMutableDictionary *dic;



if(inventoryItems.count>0){
    NSMutableArray *prods = [[NSMutableArray alloc] init];

    for (int a=0; a<inventoryItems.count; a++) {


        if([inventoryItems[a] objectForKey:@"InventoryID"]!=nil){


            UITableViewCell *cell = [_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:a inSection:0]];


            UITextField *countTextfield = (UITextField *)[cell viewWithTag:4];

            double countValue = [countTextfield.text doubleValue];

            NSNumber *count = [NSNumber numberWithDouble:countValue];

            dic = [NSMutableDictionary dictionaryWithObjectsAndKeys: [self fetchDict:@"CustomerData"][@"User_ID"], @"User_ID", count, @"manual_quantity", inventoryItems[a][@"InventoryID"], @"InventoryID", nil];


            [prods addObject:dic];
        }
    }

    NSDictionary *outerDic = @{@"Data":prods};

    if([self isInternet]){

        [self fetchPostAddress:[NSString stringWithFormat:@"http://localhost/Backend/webservice/set-inventory-manually.php"] andParameter:[self jsonconvert:outerDic]andIdentifier:@"manualInventory"];


    }
}

}

推荐答案

从自定义Cell创建自定义 UITableViewCell 类。

Create a Custom UITableViewCell class from custom Cell.

tableView:cellForRowAtIndexPath:

ConditionTableViewCell *objCell = (ConditionTableViewCell *) [tableView dequeueReusableCellWithIdentifier:@"conditionCell"];
objCell.countTextfield.text = @"Your text";
return objCell;

这篇关于自定义表视图单元格中的文本字段从初始文本字段中消失,并在滚动时显示在其他单元格文本字段中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆