After switching Views, I want my label text to remain what it was before switching - uilabel

I am really close with this. And I apologize for being so new at coding. This question is probably not the hardest thing to figure out. Here are some things you should know beforehand:
Right now I have a simple tally app for a IRL board game I'm making.
The tally app itself is not on the main View of the app. So, to get to the tally app, I click a button.
On the tally app theres an up and down button for +1 and -1.
There's a UILabel that shows this result. So when I press the up button 3 times, the label on the app says "3".
But when I go back to the main view, and then go back to the tally app, the number is still there, but it shows as "0". When I press the up button, it says "4". Not "1". So it KNOWS the state of the label, but it doesn't SHOW the state of the label. It shows 0 when I go back and forth between views.
How can I make it show the state of the label when switching views and coming back?
Here is my viewDidLoad code
- (void)viewDidLoad {
Count.text = [NSString stringWithFormat:#"%i", Number];
}

Put the same code in "viewDidAppear" as well. viewDidLoad is called only once when the view is created, not every time it appears.
In viewDidLoad, make sure to call [super viewDidLoad]; in be beginning. Do the similar in viewDidAppear.

Related

Inputs do not reset after clicking cancel button and reopening the view

I have a form with some text fields, toggles and pickers. Everything works just fine except for When I input something on text fields and click cancel button and reopen the form, inputs are still there. Just can't figure out why.
Now, the app I'm working on is huge. Therefore, can't share everything but here's how my btnCancelClicked method looks like:
- (IBAction)btnCancelClicked:(id)sender {
if(onCompletion) {
onCompletion(self.myView, YES);
}
}
What's the logic behind implementing a cancel button? What is the step by step process to close the view and not saving whatever the user input is? I'd like to understand what the problem behind this might be. I appreciate any help.
Edit: [self.myView setNeedsDisplay]; or [self.myView setNeedsLayout]; are not helping.
Edit2: TextViews are also working properly, meaning that when I type something and then click cancel and reopen the view is at its initial state. The only problem is with TextFields. Should I do something different for them?
After dismissing the view, the view is still in memory. So you get all the entered value as it is. you have two way to achieve your desired outcome:
After dismissing the view, set it to nil. create a new view while you are presenting.
Before presenting your view, programmatically reset your controls.
you mentioned TextViews are working perfectly, is TextViews created manually?

Using viewdeck, while closing leftView chenterView appears but but not reloaded

I'm using ViewDeck library to use side panel functionality and it works fine. My application needs the centerViewController to be reloaded while I click some button from LeftViewController.
and it should be reloaded after appearing the centerView.
#import TCenterViewController.h
....
- (void)ViewDidAppear:(BOOL)animated{
// code to reload the view
}
And m calling it from LeftViewController.
[self.viewDeckController.centerController viewDidAppear:NO];
Its working. but taking the time to load before the view appears. how can I reduce the delay??
I know it's a bit late, but in case someone still needs the answer. You need to insert your update code in
- (void) viewWillAppear:(BOOL)animated
this method is called every time the scene appears. However, this is not the case with viewDidLoad.

Keyboard appears on top of view where no user interaction should be allowed

I have a window-based project with two UITextFields to take input from the user.
Both are in my view controller.
I have to parse stuff in the background, so I need something that blocks user interaction in the meanwhile.
I came across this Cocoa With Love tutorial to create a loading view on top of everything. It actually works pretty well, for the most part; it works when ever the text field resigns first responder.
There is one circumstance where it doesnt work, though. When I type something in the first text field and then select the second one, the loading screen will appear, but the keyboard is on top of it, so the user could type something. I want the loading screen to be on top of the keyboard.
In the tutorial, it says to call the keyboard's superview. What is the keyboard's superview?
I tried the following different snippets in my view controller, but nothing works.
loadingView = [LoadingView loadingViewInView:[self.view.window.subviews objectAtIndex:0]];
loadingView = [LoadingView loadingViewInView:self.view];
loadingView = [LoadingView loadingViewInView:self.view.superview];
How can I make the loading screen appear on top of everything ?
The simple solution is to dismiss the keyboard when you show the loading view. I don't think you're allowed to put anything on top of the keyboard.
That said, you could try using the root window as the view to see if that has any effect.

what am I doing wrong in attempt to popup a web view and then allow user to go back

my app has tabBarController with 3 views and in one of them I want to popup a web browser with the ability to return back to the application. To do that I am using UINavigationController.
In myAppDelegate.h I have defined the property UINavigationController *nav and in myAppDelegate.m I have #synthesize nav.
In the class where the webPopup function resides upon pressing the button my code comes to this function.
- (IBAction)showWeb:(id)sender {
myAppDelegate *app=[[UINavigationController alloc] initWIthRootViewController:self];
// because I want to return back to the same view
webController *web = [[webController alloc] initWithStyle:UITableViewStypeGrouped];
[app.nav pushViewController:web animated:YES];
app.nav.view.frame = CGRect(,0,320,430);
[self.view.window addSUbview:app.nav.view];
}
The web popup occurs but it is moved vertically, when I press "back button" my former view appears as well and it is also shifted vertically from what it was before.
After going back and forth few times the thing hangs.
Questions:
1. what can cause the shift?
2. how to avoid when I go "back" to see the title(test from the "back"button, I think this might cause a shift when I go back.
3. how to find out why it hangs after few attempt?
Thanks.
Victor
The line:
myAppDelegate *app=[[UINavigationController alloc] initWIthRootViewController:self];
makes no sense to me. Surely your compiler is warning you about that? What is "myAppDelegate" defined as? Classes should have a capital letter at the front, by the way.
Also, the line
[self.view.window addSUbview:app.nav.view];
is highly suspect, because the UIWindow for your application should have only one child UIView. You shouldn't just add more views willy nilly and expect things to work. It is possible to change the child UIView by removing the old one and adding a new one, but you don't seem to be doing that. Having more than one child UIView of UIWindow gets you into trouble very quickly -- for example, device orientation changing can break.
I'm not exactly clear as to why the app delegate (or the window for that matter) needs to be messed with at all to do what you are trying to do. Sounds like you should just be using standard Nav View Controllers and Web Views.
Also, you are alloc init'ing w/o any memory management.

if parentViewContoller statement

I'm writing a program with a UITableView with and add button in the Navigation Bar which leads to an edit page. When you click on an item in the table, a view (rView) is pushed with information pertaining to that item. This view has an edit button that also leads to the edit page. Is there a way that I could put an if statement for the done button on the edit page that says "if parentViewController is the UITableView to go to rView, else popViewController?" I would assume there is a way to do this, but I'm not sure of the syntax to do so. Thanks
If I understand correctly you have a UINavigationController and push onto it
a UITableView
an "rViewController" (you can't push a view, must be a controller)
an "EditController"
But there is a possibility that step 2 is omitted and you go directly to the edit screen.
Now when the last controller is popped, you want to be able to always go to a "rViewController", even if it's not on the stack.
First of all, the parentViewController is NOT the previous controller on the stack, but rather the UINavigationController itself, so it has nothing to do with the present problem.
The way to do this is by setting the UINavigationController's viewControllers property explicitly with an NSArray. I haven't tried this but this should work:
When a user presses the "add" button, instead of just pushing the edit view controller, do something like:
NSArray* stack = navigationController.viewControllers;
navigationController.viewControllers = [stack arrayByAddingObject:rViewController];
[navigationController pushViewController:editController animated:YES];
(By the way, I would suggest not using names like "rView" except maybe for very short-lived local variables, like in a loop. Using descriptive names is very much part of the Cocoa idiom and will help you a lot in the long run.)