Note that there are some explanatory texts on larger screens.

plurals
  1. POSave Text from UITableViews
    primarykey
    data
    text
    <p><em>EDIT: Found the actual cause of the crashing. I needed to delete and reinstall to test properly without crashing as I altered the data model. However its now a case of working out how to correctly save an array with coredata. How can I do this?</em></p> <p>I have a UITableView and I want to be able to enter text into the cells then save that text in an array, then load the text back in from the array when you load the app. </p> <p>Im using CoreData but seem to be having some issues. Here is what I have thus far. </p> <p>In the cellForRowAtIndex function I am adding UITextFields as a subview of each cell so I can type in them and I can only type in them when my UISwitch, editCells, is on. Four of the cells have preset text in them which I have set.</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(15, 20, 185, 30)]; textField.delegate = self; // Configure the cell... if ([indexPath row] == 0) { [cell setAccessoryView:textField]; textField.text = @"Before School"; textField.font = [UIFont fontWithName:@"Helvetica-Oblique" size:16]; textField.enabled = FALSE; } else if ([indexPath row] == 3) { [cell setAccessoryView:textField]; textField.text = @"Break Time"; textField.font = [UIFont fontWithName:@"Helvetica-Oblique" size:16]; textField.enabled = FALSE; } else if ([indexPath row] == 6) { [cell setAccessoryView:textField]; textField.text = @"Lunchtime"; textField.font = [UIFont fontWithName:@"Helvetica-Oblique" size:16]; textField.enabled = FALSE; } else if ([indexPath row] == 9) { [cell setAccessoryView:textField]; textField.text = @"After School"; textField.font = [UIFont fontWithName:@"Helvetica-Oblique" size:16]; textField.enabled = FALSE; } else if ([indexPath row] == 1 || [indexPath row] == 2 || [indexPath row] == 4 || [indexPath row] == 5 || [indexPath row] == 7 || [indexPath row] == 8) { [cell setAccessoryView:textField]; textField.font = [UIFont fontWithName:@"Helvetica" size:16]; if (editCells.on == TRUE) { textField.enabled = TRUE; } else { textField.enabled = FALSE; } } [monArrayA addObject:textField.text]; [textField release]; return cell; } </code></pre> <p>To save I run this when the value of editCells changes, so when the user has finished editing its saved as this switched will be turned off. I make a new object to save with core data. I save the lesson which is the array with all the cell text in and the table it needs to be in, but saving its tag. But of course, this chucks up a SIGABRT error and crashes the app when flicking the switch.</p> <pre><code>[editCells addTarget:self action:@selector(editCells:) forControlEvents:UIControlEventValueChanged]; -(void)editCells:(id)sender{ [monTable reloadData]; //Create a new object to save. NSManagedObject *newLesson; //Tell it to be saved to the DatedText entity using the managedObjectContext, context_. newLesson = [NSEntityDescription insertNewObjectForEntityForName:@"TimeTable" inManagedObjectContext:self.managedObjectContext]; //Set two values within this object, being the text the user entered and the date from the datePicker. //Save these to their appropriate properties within this entity. [newLesson setValue:monArrayA forKey:@"lessonName"]; [newLesson setValue:monTable.tag forKey:@"table"]; //Create error incase of failure to save. NSError *saveError = nil; //Try and access the data store via context_ and fall back on saveError if fails. [self.managedObjectContext save:&amp;saveError]; if (saveError != nil) { //Report error by printing it to the console. NSLog(@"[%@ saveContext] Error saving context: Error = %@, details = %@",[self class], saveError,saveError.userInfo); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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