I have 3 view controllers.
N
T
C
Their layout is like so:
N
-(root view controller)-> T
-(bar button item Add - Triggered Segue)-> C
Just to clarify, T
has an "Add" button which has a triggered segue action to present C
modally.
C
and T
both have custom classes. C
is a simple UIViewController
subclass while T
is a UITableViewController
subclass.
In T
I declare an NSMutableArray
and a UITableView
like so:
@interface T: UITableViewController {
NSMutableArray *myTableData;
IBOutlet UITableView *myTableView;
}
In C
I have two elements within:
UITextField
UIButton
called "send"
I connect the text field to an IBOutlet like so in C
's header, as well as create an action for the button:
@interface C: UITableViewController {
IBOutlet UITextField *itemToAdd;
}
-(IBAction)addItem:(id)sender;
So I have the data array myTableData
which populates T
's table declared and initialized in T
(I will add a myTableData = [[NSMutableArray alloc] init]
in the viewDidLoad
method of T
.
When the "add" button in the navigation bar of T
is clicked it will obviously bring up C
and take in some text from the text field.
Then finally when the send button is pressed I want to add that text from the text field into the myTableData
array, dismiss C
(which I plan on doing with [self dismissViewControllerAnimated:YES completion:nil]
, and update the table view myTableView
to reflect the changes that I have made.
Does anyone have any idea on how I could accomplish this? Mainly I need help somehow accessing myTableData
(that lives in T
) FROM C
. Then I need to get T
to recognize that some change has been made and to redraw its cells (probably by instigating cellForRowAtIndexPath). I am aware of how to do this all hardcoded Apple's docs, but I find that method isn't viable if you want to visually represent everything in the storyboard and they do not explain what everything means exactly (like itemInputController for instance).
If my approach is totally incorrect and I don't need all these classes or methods or am doing it all wrong, please feel free to give me a similar approach using the storyboard.