1

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.

user3178926
  • 339
  • 1
  • 5
  • 15

1 Answers1

0

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.

Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143
  • Yes this works if I were to go into ControllerA from firstViewController but it is not what I'm looking for if I get to ControllerA from secondViewController because I want to pop back to firstViewController every time I click the button in my CustomTableCell. – user3178926 Mar 06 '14 at 20:23
  • Thanks for helping. but I think it's crashing because there is a delegate between firstViewController and controllerA. Error Message: -[FirstViewController recordCardNumber:recordCheckInID:]: unrecognized selector sent to instance 0xa503650 – user3178926 Mar 06 '14 at 20:30
  • Do you know how I can solve this issue? recordCardNumber:recordCheckInID is a delegate function in firstViewController – user3178926 Mar 06 '14 at 20:31
  • Update your question with code when you are setting the delegate and passing data to it. It's hard to tell without looking into the code. – Rafał Sroka Mar 06 '14 at 20:38