Textfield in Custom Table View Cell dissappears from initial textfield and appears in other cells textfield upon scrolling

- (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;
}

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"];


    }
}

}

  • How to debug app in compatibility mode on iOS 7?
  • How to Implement Swipe Left to Right in UITableView Cell similar to iOS Mail
  • Objective C - Manual Array FIFO Queue
  • How to execute a block of code in IOS7 not in IOS6?
  • How do I hide the status bar in a Swift iOS app?
  • iPhone: How can I build my own TabBar?
  • Solutions Collect From Internet About “Textfield in Custom Table View Cell dissappears from initial textfield and appears in other cells textfield upon scrolling”

    Create a Custom UITableViewCell class from custom Cell.

    In tableView: cellForRowAtIndexPath:

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