0

I (think) I have researched this problem extensively in Apple's docs and online, both here and elsewhere. However, after several hours of troubleshooting I am out of ideas. My Modal view controller refuses to dismiss itself at the appropriate time.

I am aware that modal controllers must be dismissed by the controller that presented the modal view, and as far as I can tell, that's what I am doing.

The problem:


This is the code contained in prepareForSegue for the presenting viewcontroller, in its entirety:

if ([segue.identifier isEqualToString:@"DISCREPANCYVC"]) {

    DiscrepancyViewController *destController = segue.destinationViewController;
    destController.discrepancyDelegate = self;
}

The modal controller contains two UIPickerViews, which are behaving properly. The picker views are used to construct "classificationString", an NSString.

I have a "Done" button on the modal view, which, when pressed, calls this method/selector (as per the protocol definition that I've set up):

[self.DiscrepancyDelegate didFinishWithClassification:classificationString];

The didFinishWithClassification method appears as follows:

- (void)didFinishWithClassification:(NSString *)classification {

    [self dismissModalViewControllerAnimated:NO];

If it matters, the protocol is defined as

@protocol DiscrepancyViewControllerDelegate <NSObject>
@required
    - (void)didFinishWithClassification:(NSString *)aClassification;

@end

The property that holds the reference back to the presenting view appears as:

@property (strong, nonatomic) id <DiscrepancyViewControllerDelegate> DiscrepancyDelegate;

There are four additional properties (strong, nonatomic) which are used to house the four arrays that populate the UIPickerViews (each picker has two components).

I have tried both animated and non-animated dismissals with no change in behaviour.

What could be causing this? I am using ARC, so it's not up to me to release anything before trying to dump the modal screen, correct? And from what I have read, viewDidUnload() will not necessarily fire in this situation (and it is not firing in my case).

Help!!

Thx,

Ted

2 Answers2

0

There are 9 steps required to make a delegate protocol work. Check them all in my answer here.

Also, the statement: "I am aware that modal controllers must be dismissed by the controller that presented the modal view" is not true. It is suggested as good form, but you can put the dismiss statement in the modal view controller and if you have no other reason for having a delegate then I would do so rather than enduring the complexity of setting up a delegate protocol.

Community
  • 1
  • 1
T.J.
  • 3,942
  • 2
  • 32
  • 40
  • I have verified all my steps against the Wenderlich site, and they are all in compliance. I've changed the deprecated dismissModal call to dismissViewController, with no change in behaviour -- the screen still does not go away. What else could be causing the screen to persist? Anyone? – NightStalker Feb 27 '12 at 23:50
0

I figured it out; sort of. I must have had an Outlet erroneously connected, or a duplicate connection of some sort, because after trashing all the connections between the buttons and the controller, and the pickers and the controller, and then resetting them, it started working. I don't know exactly what I did (which is now driving me crazy) but it was not a coding problem.

Word of advice: Go over connections with a fine tooth comb. They can mask problems without presenting themselves as errors.

Grrrrrrr.