Note that there are some explanatory texts on larger screens.

plurals
  1. POsave TextField content in an custom dynamic tableView
    text
    copied!<p>I've got a custom TableViewCell with a dynamic tableviewcontroller <a href="http://i44.tinypic.com/6dtr3l.jpg" rel="nofollow">screenshot of my app</a></p> <p>the products are saved in CoreData and i can fetch them (Name,price etc.) but i don't know how to implement the amount of the products. its a textfield and i want to save the textfield when i click on the basket button.</p> <p>here is my TableViewCell.h:</p> <pre><code> #import &lt;UIKit/UIKit.h&gt; @interface ProduktTableViewCell : UITableViewCell &lt;UITextFieldDelegate&gt; @property (nonatomic, weak) IBOutlet UILabel *produktnameLabel; @property (nonatomic, weak) IBOutlet UILabel *preisLabel; @property (nonatomic, weak) IBOutlet UILabel *vonDatumLabel; @property (nonatomic, weak) IBOutlet UITextField *menge; @property (nonatomic, weak) IBOutlet UILabel *bisDatumLabel; @property (strong, nonatomic) IBOutlet UIButton *datumButton; @property (strong, nonatomic) IBOutlet UIButton *warenkorbButton; @end </code></pre> <p>TableViewCell.m:</p> <pre><code> #import "ProduktTableViewCell.h" @implementation ProduktTableViewCell @synthesize produktnameLabel; @synthesize preisLabel; @synthesize vonDatumLabel; @synthesize bisDatumLabel; @synthesize datumButton; @synthesize menge; @synthesize warenkorbButton; @end </code></pre> <p>my ProductViewController.m:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ProduktTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"produktCell"]; NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath]; cell.produktnameLabel.text = [managedObject valueForKey:@"produktname"]; cell.vonDatumLabel.text = [managedObject valueForKey:@"vondatum"]; cell.bisDatumLabel.text = [managedObject valueForKey:@"bisdatum"]; cell.datumButton.tag = indexPath.row; cell.warenkorbButton.tag = indexPath.row; cell.menge.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; } </code></pre> <p>my basket button:</p> <pre><code>- (IBAction)warenkorbButton:(id)sender { NSManagedObjectContext *context = [app managedObjectContext]; UIButton *button = sender; NSInteger rowInIndexPath =button.tag; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:rowInIndexPath inSection:0]; Warenkorb *warenkorb = [NSEntityDescription insertNewObjectForEntityForName:@"Warenkorb" inManagedObjectContext:context]; Produkt *produkt = [self.fetchedResultsController objectAtIndexPath:indexPath]; warenkorb.produktname =produkt.produktname ; warenkorb.vondatum = produkt.vondatum; warenkorb.bisdatum = produkt.bisdatum; warenkorb.preis =produkt.preis; NSError *error; if (![context save:&amp;error]) { NSLog(@"Fehler beim hinzufügen : %@", [error localizedDescription]); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload