How to assign copy of object back to original reference?


How to assign copy of object back to original reference?



I have application with following design: Table View that lists documents. And ViewController where document is edited.

When editing the document I want to use a copy of object so in case user press Cancel I just throw away the copy. If user selected Save I copy modified document to original. (I can't have all document's fields as properties in viewController because there are too many of them).

Table View controller:

SelectedRowAtIndex {   document= [documentsArray objectAtIndex:indexPath.row];   viewController.assignedDocuemnt= document; } 

Then I have View controller class where the item is modified:

@interface @property (nonatomic,retain) Document *asignedDocument; @property (nonatomic,retain) Document *editedDocument;  viewDidLoad{    editedDocument= [assignedDocuemnt copy]; }   IBAction save {    assignedDocument=editedDocument; } 

My problem is that original document in documentsArray is not updated with edited version. What did I miss?




Mono on the iPhone?

1:



Date Picker for iPhone Web Application
You're copying the value and then assigning the reference of the copy back over a reference to the original.


Best analytics offering for iPhone
That's definitely not going to work..
C makefile to compile OpenGL project directly on iphone
First, keep track of which document they're adding in the table view's viewcontroller..
Checking online status from an iPhone web app
Then add a handler for replacing the selected document with another to the table view's viewcontroller:.
How to create a GUID/UUID using the iPhone SDK
- (void)replaceSelectedDocument:(Document*)newDoc {     [documents replaceObjectAtIndex: editingIndex                          withObject: newDoc]; } 
To save, call the table view controller's new message from the editor view controller with something like:.
Accessing image data from a bitmap given a pointer
[tableViewController replaceSelectedDocument: editedDocument]; 
A better way to do this would be to modify your editor view controller to take a target and action instead of calling back to the table view controller explicitly.


What is better: Global string or singleton?
When you want to save, call the action:.
[target performSelector: action withObject: editedDocument]; 
But that's another bump on the learning curve that you probably don't need to get over today..



74 out of 100 based on 59 user ratings 784 reviews

*