I'm a little new to iOS development. I have these methods declared and implemented in two separate view controllers (a Master view controller and an Editor view controller) and need to pass data through from the editor to the master. The master contains a table view that needs to update with the appropriate name. (Note: I used the default Master-Detail Application template for iPhone. I didn't manually create this with the Single-View Application)
Currently, the UITableView inside the MasterViewController doesn't update with a new cell. It's been such a hectic week for me, I must just be missing something. Here's the code for the Master View Controller:
@implementation FTMasterViewController
@synthesize bPlusMinusField, cPlusMinusField, cTerm, bTerm;
-(void) passTrinomial:(CCTrinomial *)tri withBPlusMinusField:(NSString *)bField withBTerm:(double)bTermField withCPlusMinusField:(NSString *)cField withCTerm:(double)cTermField {
//allocate the array
if (!self.trinomials) {
self.trinomials = [[NSMutableArray alloc] init];
}
//set Master VC properties to tri fields passed in
self.bPlusMinusField = bField;
self.cPlusMinusField = cField;
self.bTerm = bTermField;
self.cTerm = cTermField;
NSString *trinomial = [NSString stringWithFormat:@"x² %@ %g %@ %g", bPlusMinusField, bTerm, cPlusMinusField, cTerm];
[self.trinomials insertObject:trinomial atIndex:0];
NSLog(@"%lu", (unsigned long)[self.trinomials count]);
}
#pragma mark - Table View
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.trinomials count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.textLabel.text = [NSString stringWithFormat:@"x² %@ %g %@ %g", bPlusMinusField, bTerm, cPlusMinusField, cTerm];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSDate *object = _objects[indexPath.row];
[[segue destinationViewController] setDetailItem:object];
}
}
@end
This is the code that I deemed necessary to see to fix the problem: obviously, I have the default overridden methods in the rest of the implementation.
This is the Editor View Controller code. When the thought appears for you, yes, the "done" button is linked to the -handleDoneButtonPushed: method in my Main Storyboard.
-(IBAction)handleDoneButtonPushed:(id)sender {
[self dismissViewControllerAnimated:YES completion:NULL];
FTMasterViewController *masterVC = [[FTMasterViewController alloc] init];
[masterVC passTrinomial:factoring withBPlusMinusField:bPlusMinusField.text withBTerm:[bTriField.text doubleValue] withCPlusMinusField:cPlusMinusField.text withCTerm:[cTriField.text doubleValue]];
}
This editor view controller simply gets some values in the form of a UITextField and hands them off to the Master View Controller through an object of that class. Again, when I click the Done button on my top nav-bar, it dismisses the Editor View Controller but doesn't update the table view with those values retrieved.
Help would be greatly appreciated. :)