I'm new to programming and some OOP concepts and am not sure what is the "right" way to do something. Basically what I have is an NSMutableArray in my mainViewController.
MainViewController: UITableViewController
@property (nonatomic, retain) NSMutableArray *data;
A plus button can be pressed to add an item to the Table, or if an already existing row is selected, the current item can be edited. I'm not sure what the best way to structure my DetailViewController since the DetailViewController can be presented from either the plus button or a table row selection. Do I set a flag in DetailViewController that says which method presented the DetailViewController so in my Save method, I either insert the object (if the user pressed plus), or replace the object at the current index (if the user selected a row and I passed the index to the DetailViewController)? It seems kind of clunky to do it that way and was wondering what a better way to do something simple like that would be. Thanks!
Your current MainViewController
setup is fine. What you want to do for your DetailViewController
is define its own view. Given the description of your app it would be best if you stored each row in your table as an object:
MainViewController: UITableViewController
@property (nonatomic, retain) NSMutableArray * data ; // an entry for each row
DetailViewController: UIViewController
@property (nonatomic, retain) SomeObject * object; // Represents a single row
When presenting your DetailViewController either:
When your detail view controller is done, you refresh the table view.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.