Ignoring viewDidAppear when dismissing a modal view via a delegate - xcode

I have a delegate on my modal view controller which activates the following on my parent view
- (void)userTappedOnBackButton
{
[self dismissModalViewControllerAnimated:YES];
}
This successfully dismisses the view.
On the main view's didAppear, data is loaded and a table is bound.
How can I inform the view not to reload this data if the view is displayed via this route?

Set a flag in the parent view controller like self.hasModalOnTop = YES before presenting modal view controller. And check this value in viewDidAppear like this.
if(!self.hasModalOnTop) {
// load data and bind table
}
self.hasModalOnTop = NO;
A little bit hacky, but should work.

Related

Could not set the title of tableview

I embedded tableviewcontroller into a navigation controller, set the title, but it does not show when I run the app.
What is wrong?
This is the setting of the tableviewcontroller
Here is the setting of the navigation controller
First check, your NavVC must be initial VC.
If not then try this piece of code
-(void) viewWillAppear:(BOOL)animated {
[[self navigationController] setNavigationBarHidden:NO animated:YES];
}
you must be presenting the plain table view instead of navigation controller. What you need to do is make you tableview as root view for a navigation controller and present the navigation controller.
var nav: UINavigationController = UINavigationController(rootViewController: vc)
//then present the nav
Change the initial VC from Navigation Controller to your TableViewController
I did not set the StoryboardId for Navigation controller.

OS X - How can create only one window using segue and preserve data?

I have two View Controllers. First one have sendbutton that segue to second view controller. Action Segue is Show. Each time click the button, new window pops up again. I don't want create new window again, and I just want to only one second View Controller.
And my FirstViewController.m :
- (void)prepareForSegue:(NSStoryboardSegue*)segue sender:(id)sender{
SecondViewController *destinationScene = [segue destinationController];
destinationScene.receivedString = _nextOne.stringValue;
}
SecondViewController.m :
- (void)viewWillAppear{
if(_myMutableArray == nil) _myMutableArray = [NSMutableArray array];
[_myMutableArray addObject:_receivedString];
}
What I want to is send a string in the first View Controller's TextField repeatedly to next View Controller. And keep using only one second window that created at first time.
See my Storyboard
You can do this in IB without any code. Update the Presentation attribute for the view controller in the destination view from Multiple to Single:
https://stackoverflow.com/a/36104388/287963
Don't set up the segue to happen automatically. Create an IBAction for the button, test whether your second view controller is already on the screen, and either segue or not depending on whether it already exists.

What is the statement to go from one ViewController to another ViewController AFTER I have selected an item from my UIPickerView?

I have an initial view controller. It goes to the next view controller which has the “picker wheel” in it. From that screen, if the user selects one of the 4 items in the picker wheel and stops on it. Then press ONE action button to initiate several C code statements.
I need specific help with coding the statement (s) that cause the transition from one view controller to another view controller.
I’m thinking out loud, it should look something like this (but I really don’t know):
‘If row = 0 then go to View controller B.’
‘If row = 1 then go to View controller C’
etc.
Or use some other ‘VERY SIMPLE’ method for transitioning from a ‘selection from a picker wheel to another view controller’.
Basic documentation.
I have 4 viewcontrollers :
First view controller is named - VCa
Second view controller is named - VC1
Third View controller is named - VCb
Forth view controller is named - Vcc
There is nothing but the default 'Storyboard" coding in this VCa (view controller).
The first view controller only has a label named VCa , so we can see which VC this is.
And it has a button named Button A, so I can do a modal segue to the next view controller named VC1.
The second view controller (VC1) only has some basic things.
The picker wheel named pickerView1. The array named Companies with data.
A button to go back to the first view controller VCa.
The button is named B1Back.
A button to go forward to the next view controller named VCb.
The pupose for this button is only for demo. purposes to transition to VCb.
It has nothing to do with coding a solution to allow the picker wheel selection to . transition somehow to the next view controller.
The button is named B1forwardtob.
The same is true for the 3rd button. It just allows this VC (VCa) to transition to . . another view controller named VCc. The button is named B1forwardtoc.
An ACTION button that does nothing, yet. I’m hoping the transition from view controller to view controller code goes here (after the action button). But again I don’t know what I don’t know.
There is nothing but the default 'Storyboard" coding in this VCb (view controller).
The third viewcontroller (VCb) is very simple too. It is there just to go to and then go back to VC1.
There is nothing but the default 'Storyboard" coding in this VCc (view controller).
Same for the forth viewcontroller (VCc). It is there just to go to and then go backto VC1.
It's sort of hard to tell what you're asking, but are you looking for something like this?
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
UIViewController *viewControllerToDisplay;
if (row == 0) {
viewControllerToDisplay = [[ViewControllerB alloc] init];
} else if (row == 1) {
viewControllerToDisplay = [[ViewControllerC alloc] init];
}
if (viewControllerToDisplay) {
[self presentViewController:viewControllerToDisplay animated:YES completion:nil];
}
}

How to move from last view to any view in view controller hierarchies

Suppopse there are five view as A,B,C,D,E i am presenting view A to B then B to C using present view controller method. Now i want to dismiss view controller form View C to A directly. How we can do this
One way to do this (and perhaps the simplest) would be to use a UINavigationController and push UIViewControllers onto it.
Then you can simply call: [[self navigationController] popToRootViewControllerAnimated:YES];
Another more complex way to handle this if you really want modal view controllers would be to set up the UIViewControllers with callbacks to register that they should close immediately on next appearance.
-(void)closeImmediately
{
mCloseImmediately = YES;
}
-(void)viewWillAppear:(BOOL)animated
{
if(mCloseImmediately)
{
[self dismissModalViewControllerAnimated:NO];
return;
}
// ... other normal setup code
}
Doing this in viewWillAppear and without animation means that this UIViewController never gets displayed.

Modal view controller inside master tableview (and dismiss keyboard)

I know this is a very popular issue, but i´m having a hard time...so if anyone could help, it would most appreciate:
Im my master tableview (that i have made in storyboard) i have a plus button and every time the user presses that button, a picker view appears...depending on the selection in the picker view, a modal view appears (for this modal view, i have dragged a simple view controller in storyboard and gave it a storyboard id). Each modal view has textfields, and i want to dismiss the keyboard every time the user enters something...to create the modal view i have done this:
CobTableview *produtoCob =[self.storyboard instantiateViewControllerWithIdentifier:#"cobId"];
produtoCob.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:produtoCob animated:YES completion:nil];
produtoCob.view.superview.frame = CGRectMake(0, 0, 350, 512); //do this after presentModalViewController
produtoCob.view.superview.center = self.view.center;
produtoCob.managedObjectContext = self.contextProd;
How can i resolve this?
To everyone that has the same issue...i found out that you need both methods in your modal view controller class :
- (BOOL)disablesAutomaticKeyboardDismissal
return NO
-(BOOL)textFieldShouldReturn:(UITextField *)textField
([textField resignFirstResponder];
return yes

Resources