0

I have a view (viewControllerA) that has a textbox. The user populates it and clicks Next. After completing a few steps, they're done/submit all data and I want to pop them back to viewControllerA, but when I do, the textbox is still populated. I don't want to clear on viewWillAppear because I want to use the built-in back button functionality. How can I clear that textbox only after popToViewController?

[rootController popToViewController:rootController.transferScanPartView animated:YES];
btorkelson
  • 89
  • 2
  • 10

1 Answers1

0

There are a variety of ways in which you can do this. What I post below is my second attempt, which I think is simplest here. Have a block in your vc, something like

@property (nonatomic,strong) void ( ^ appearBlock )();

and then use that to do whatever you want next time the view appears. The first time this will be nil and will not execute, then when you call the code you posted also do something like

__weak myVc * weakSelf = self;
self.appearBlock = ^ { weakSelf.edit.text = nil; };
// Code you posted, where you present your popover
[rootController popToViewController...

and in your viewWillAppear

- ( void ) viewWillAppear ...
{
  [super viewWillAppear...

  if ( self.appearBlock )
  {
    // Execute block
    self.appearBlock();

    // Ensure we never call it again
    self.appearBlock = nil;
  }

  .. rest of view will appear ..
}

EDIT

The trouble here is that, depending on the iOS you use and how you present the vc, a number of things are called or not called when the view is presented or dismissed.

Depending on that you may have to move the call to the appearBlock to different places. The popover delegate can be used but I don't think iOS 9 supports that, then for popovers you also have the beingPresented / beingDismissed messages.

skaak
  • 2,988
  • 1
  • 8
  • 16