1
votes

In a storyboard I have 3 view controllers: firstViewController, secondViewController, and controllerA.

Both firstViewController and secondViewController have a navigation right bar item that presents controllerA using segues in storyboard.

controllerA has a tableView with custom table cells. In the customTableCell.xib, there is a acceptButton that stores data and pops back to firstViewController. I am able to implement this only if the user go from firstViewController to controllerA by using popViewController.

EDIT: But I am not able to do it if the user gets to ControllerA from secondViewController, because popToViewController would not work. I tried using:

FirstViewController *recordViewController = [[FirstViewController alloc] init];
[self.navigationController pushViewController:recordViewController
                                     animated:YES];

EDIT: I'm getting a crash with this error:

__NSArrayM insertObject:atIndex:]: object cannot be nil'

[SecondViewController recordCardNumber:recordCheckInID:]: unrecognized selector sent to instance 0x17d97250'

There is a delegate relationship between controllerA and firstViewController.

How can I implement this properly?

EDIT: this is the delegate in FirstViewController:

#pragma mark - ControllerADelegate

- (void)recordCardNumber:(NSString *)number recordCheckInID:(NSString *)checkInID
{
self.CardNumbertext.text = number;
NSLog(@"record card# %@", self.CardNumbertext.text);
}

I am passing the data through and popping to firstViewController successfully if I use

[self.delegate recordCardNumber:number recordCheckInID:checkInID ];
[self.navigationController popViewControllerAnimated:YES];

It just crashes if I enter controllerA from SecondViewController because I want to go back to firstViewController once the acceptButton is pressed.

1

1 Answers

0
votes

To show the first view controller on button tap:

FirstViewController *recordViewController = [[FirstViewController alloc] init];
[self.navigationController pushViewController:recordViewController
                                     animated:YES];

However, the cause of the error you are getting:

__NSArrayM insertObject:atIndex:]: object cannot be nil

is most likely not connected with popping to previous view controller but updating an array on the button tap. Check the code which is fired when you tap the button. Most likely you are adding an object that is nil to a NSMutableArray.