0

So I have an app that populates a table from a shared store and when you click on a row it preforms a segue to more information and you can edit the item you clicked on(basic master-detail). For some reason once you edit the item and go back (I'm using a navigation controller as my root view) the change shows (in the app and in memory from as far as I can tell) until you refresh the data in the table(I refresh every time the view appears or new information is added to the table aka another row is added). All of the items properties show null or 0 even the ones you do not edit.

I have put NSLogs and breaks to try to find out whats going on but to no avail. If i do not try to save any changes made to the item in the detail view controller they will not be null but i have to be able to make changes and grab user input.

My problem seems similar to this thread iOS Master Detail app - detail shows only the first time but I do not understand the solution that was posted.

can anyone explain maybe what this solution is or know how to fix this problem?

any help would be appreciated!!

If you need a section of code please ask.

this is how I save the "feedItem" in the detail view controller

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];

// Clear first responder
[self.view endEditing:YES];


// "Save" changes to item
BYFItemFeed *item = self.item;
item.amount=self.amountField.text ;
item.netEnergyM=self.netEnergyMField.text ;
item.netEnergyG=self.netEnergyGField.text ;
item.crudePro=self.crudeProField.text ;
item.calcium=self.calciumField.text ;
item.phosphorus=self.phosphorusField.text ;
item.cost=self.costField.text ;
}

this is how I transfer from the master to the detail

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"BYFFeedDetail"])
{



    NSIndexPath *indexPath = [[self tableView] indexPathForSelectedRow];
    NSMutableArray *items= [[BYFFeedStore sharedStore] allItems];
    BYFItemFeed *object = items[indexPath.row];
    [[segue destinationViewController] setItem:object];

   }
}


 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {



[self performSegueWithIdentifier:@"BYFFeedDetail" sender:self];
}

and this is how I populate the table

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Get a new or recycled cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];

// Set the text on the cell with the description of the item

BYFItemFeed *item = [[BYFFeedStore sharedStore] allItems][indexPath.row];
//  NSLog(@"\n\n %@",item);
cell.textLabel.text = [item description];


return cell;
} 
Community
  • 1
  • 1
  • Your question seems to be saying that you "go back" by using a push segue to present a new copy of the previous controller. If that's what you meant, that **is** your problem. If it's not what you meant, then my question would be: How **do** you return to the previous controller? – Phillip Mills Aug 19 '14 at 12:21
  • A navigation controller is my root view so all the user should have to do is tap the "back button" that appears in the top left when the detail controller is pushed onto the stack – user3431724 Aug 19 '14 at 12:38
  • Sounds good…the question is clearer now. Since you say it depends on whether or not you save changes, maybe that's a place to start with showing code, especially how it relates to whatever you're using to populate your cells. – Phillip Mills Aug 19 '14 at 12:51
  • I added the codes for master to detail transition, how i save the items in the detail controller, and how I populate the table. – user3431724 Aug 19 '14 at 13:05
  • I'm sorry to say, that looks remarkably reasonable. :) Is there any chance that your `[BYFFeedStore sharedStore]` isn't truly a singleton…how about logging its address at the points where it's giving you good data and bad? (Yes, I'm running out of superficial ideas.) – Phillip Mills Aug 19 '14 at 13:25
  • Thanks! other than the private initializer that only happens once and only being able to change the mutable array through the defined methods I am not sure what else would make it a singleton. All I can tell is that for some reason it seems to save till I reload the data with [self.tableView reloadData]; and then its null – user3431724 Aug 19 '14 at 13:44
  • If you're using something like `dispatch_once` in that private initializer, you're safe, as far as I know. Printing the addresses is thread-related paranoia. – Phillip Mills Aug 19 '14 at 14:17
  • ya I know for sure I only create it once – user3431724 Aug 19 '14 at 15:15

0 Answers0