0

I have a tableview and a detailview and I can pass data from my tableview to the detail view by including the detail view.h and setting some values from distance with initWithNib.

DetailView *detailView = [[DetailView alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];

//passing data gekozenSpel

detailView.gekozenSpel = [tableData objectAtIndex:indexPath.row];

But now I have a data table with multiple entries and one of then is set, that is: can be changed, in the detailview, from 0 to 1 or from 1 to 0, as a string. It works all fine but now I want to apply the change backwards to the table view and that doesn't work.

myTableView *myTableview = [[myTableView alloc] initWithNibName:@"myTableView" bundle:[NSBundle mainBundle]];

[myTableView.theTable replaceObjectAtIndex:location withObject:value];

For if you use an initWithNib way-of-doing then you create a new empty table nsmutablearray. But I want to CHANGE a value in that array at a specific location with a specific content.

Maybe a singleton to access the data from everywhere? I tried but I have to create instances of what I declare as value and then it is private and not public. So I don't understand how you apply a singleton then.

Any help would be appreciated,

Jan

0x8badf00d
  • 6,391
  • 3
  • 35
  • 68
Pip
  • 159
  • 2
  • 9
  • Register for a notification, use NSNotificationCenter and pass the new value and its place in the userInfo parameter of the call. –  Jun 03 '12 at 14:19
  • Call a method of your view controller and tell it to change what you want changed. – Hot Licks Jun 03 '12 at 14:57
  • So, you mean, I write a method in the tableview to change data at index and then call this method from detail view while passing arguments index and value? – Pip Jun 03 '12 at 15:11

2 Answers2

0

You will need to add a delegate to the DetailView, this delegate will pass a new array to the old view, this array will have the new tableData that you will replece

For more information on the delegate, here are some tutorials http://www.roostersoftstudios.com/2011/04/12/simple-delegate-tutorial-for-ios-development/ How to use custom delegates in Objective-C

Simple Delegate Example?

Community
  • 1
  • 1
Omar Abdelhafith
  • 21,163
  • 5
  • 52
  • 56
  • No need for a whole separate delegate -- just add a method to the VC and call it. – Hot Licks Jun 03 '12 at 14:58
  • 1
    @HotLicks is that the right way to do it? coupling views is always a bad thing :) – Omar Abdelhafith Jun 03 '12 at 15:03
  • Not "always" -- in this case there's a definite parent-child relationship. And using the delegate is still "coupling", just obfuscating the link. – Hot Licks Jun 03 '12 at 18:22
  • Passing the parent to the child is much more coupled than passing an interface to a delegate back from the child to the parent, viewcontrollers that you think today are just for this project could become more general tomorrow – Omar Abdelhafith Jun 03 '12 at 18:46
  • Could, rarely do. And the delegate will require five modifications before then, each requiring changes to six files (unless you make the class its own delegate, which gives you a warm feeling but still couples things just as tightly as without the delegate fiction). – Hot Licks Jun 03 '12 at 22:03
  • your answer is right i never disagreed with you, but what am saying is doing the right thing would save you from future additional refactoring, tomorrow he may need to pass other values, if he needed to do that, what would you suggest him to do? – Omar Abdelhafith Jun 03 '12 at 22:09
  • Enhance the interface again, just as he'd do with the delegate. – Hot Licks Jun 03 '12 at 23:29
0

I replace in the detail view the property (eigenschap) of the heart symbol (favourite: YES or NO), then that whole array is put over the mother array (dataVoorMijnTabel) to have it updated back into the main table view (mijnTabelView).

[eigenschappendata2 replaceObjectAtIndex:locatiehartje withObject:eigenschaphartje];

mijnTabelView *mtb = [[mijnTabelView alloc] initWithNibName:@"mijnTabelView" bundle:[NSBundle mainBundle]];

mtb.dataVoorMijnTabel = eigenschappendata2;

Pip
  • 159
  • 2
  • 9