I created a custom UITableViewCell
with a UITextField
, UILabels
and UIButtons
. When I enter a value to a UITextField
and scroll down, it disappears and shows in another random cell. The same problem happens with my UIButton
, when I press it, the state is changing but after I scroll down, it disappears.
Here is my cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"produktCell";
//NSString *CellIdentifier = [NSString stringWithFormat:@"produktCell %d",indexPath.row];
ProduktTableViewCell *cell =(ProduktTableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSLog(@"wird neu erstellt");
cell = [[ProduktTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.produktnameLabel.text = [managedObject valueForKey:@"produktname"];
if ([[managedObject valueForKey:@"vondatum"] length] > 1){
cell.vonDatumLabel.text = [managedObject valueForKey:@"vondatum"];
cell.bisDatumLabel.text = [managedObject valueForKey:@"bisdatum"];
}else {
cell.vonDatumLabel.text = dateString;
cell.bisDatumLabel.text = dateString1;
}
cell.datumButton.tag = indexPath.row;
cell.warenkorbButton.tag = indexPath.row;
cell.menge.tag = indexPath.row + 437812;
cell.mengeLabel.text = [managedObject valueForKey:@"mengelabel"];
cell.produktnameLabel.tag = indexPath.row +22333;
cell.mengeLabel.tag =indexPath.row;
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
NSLocale *german = [[NSLocale alloc] initWithLocaleIdentifier:@"de_DE"];
[formatter setLocale:german];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[formatter setMinimumFractionDigits:2];
[formatter setMaximumFractionDigits:2];
NSNumber *firstNumber = [managedObject valueForKey:@"preis"];
cell.preisLabel.text = [formatter stringFromNumber:firstNumber];
return cell;
}
EDIT: i fixed my problem with the textfield. i just delete the method:
/*- (void) scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
[[self.tableView superview] endEditing:YES];
}*/
but there is still a problem with my button.