I have a problem, I dont know why but my data-init function in a main view is being called when I navigate back to that page for the first time. I want to separate some initialization logic from show logic in the starting view.
View is defined as a first (and only) view inside the body element.
<div data-role="view" id="..." data-model="..." data-init="initFnc" data-show="show">
</div>
I create the app like this:
var app = new kendo.mobile.Application(document.body, { transition: "slide" });
So once again sequence of events, just to be clear:
app started, main view opened -> init and show functions called
navigate away to another view, navigate back -> init and show functions called
navigate away to another view, navigate back -> show function called
In step 2, I want to call only the "show" function.
Thanks!
This behaviour is not normal - the init event should be fired once. Most likely your navigation goes wrong and loads your homepage as a remote view. Or you instantiate the app multiple times.
That does not seems to be the case, what you shared looks completely valid. Take a look in this demo.
Related
The sample code for UIDocumentBrowserViewController has a comment in documentBrowser:didRequestDocumentCreationWithHandler: that says Optionally, you can present a template chooser before calling the importHandler.
But how? If I instantiate a view and its controller to use for selecting a template, and call presentViewController:animated:completion: on it, the code doesn't wait for the presented view to be dismissed, but continues happily on. So how can I wait for the the user to select a template in the presented view?
I figured it out. The trick was to realize that there is no need to call the importHandler block already in the documentBrowser:didRequestDocumentCreationWithHandler method. You can store the block in an instance variable of the object you use to select a template (in my case, an instance of a class derived from UICollectionViewController), present that dialog, return, and then call the stored importHandler block much later in the suitable method of that template selection class, in my case the collectionView:shouldSelectItemAtIndexPath.
See code here
I'm using Mvvm-Light to create a binding to a UIButton with the SetCommand extension. I can just call it in ViewDidLoad(...) but I want to connect it in ViewWillAppear(...) and disconnect it in ViewWillDisappear(...) like I do with the rest of my bindings. So all bindings are only active when the view is visible. If I do it this way currently then SetCommand is called every time I navigate back to the view and the RelayCommand is fired multiple times, once for every call to to SetCommand.
Is this possible? And if not, then why not?
Why do you want to disconnect a command?
If a UIViewController has disappeared, all of his controls can't be touched and seen. So the command will only fire when it appears again, I think this has already fitted your request.
If you do want to remove this command in the event ViewWillDisappear() you can use:
button.RemoveTarget(null, null, UIControlEvent.AllEvents);
This will remove all the events the button has. As you say when you SetCommand() again in the event ViewWillAppear() the RelayCommand will only be called once.
I have a pure dynamic page page1VC (which is parent) where i have few buttons which takes them to page2VC, page3VC, page4VC
There is next button and back button in every view controller (no back button in p1VC as this is parent)
I can navigate to any viewController from any other vc i.e, from p1VC -> p2VC -> p4VC -> p3Vc
on tap of back in any view controller, that takes me to p1VC
page1VC gets all info to display from API and stores in variable p1APIInfo
On tap of back button from page2VC or page3VC or page4VC --> this should take me to page1VC
My question is:
As my page1VC is pure dynamic, on 1st landing of this page, i get all info from API
When I navigate to page4VC and on tap of back it should take me to page1VC and here i dont want API to be called anytime when user taps back button
As of now i have a dummy variable in page1VC which is copy of p1APIInfo variable (say dummyAPIInfo)
Each time when i tap next im passing that variable to another VC, and on tap of back from that VC im passing back that variable. So basically this variable is to only transport data to other VC and get it back to page1VC on tap of "back" button. Im not using any data in this dummy variable in page2VC/page3VC/page4VC
However this works, but this is not best practice.
I can think of saving my page1 data in userdefaults/singleton but im looking for more optimizing solution
pls suggest how to handle
So to summarize: I want my API call to happen only once i.e., during 1st time landing..after that whenever user visits/tap back button from some other page, i need a way not to call API. It should use same data that user gets during 1st API call.
Hope I'm clear with my question. Pls advice
Make sure you do the calls in a function that isn't called multiple times. For instance, if your api calls are in the viewWillAppear method, you'll do a fetch every time you pop your navigation stack. Putting the api calls in viewDidLoad will ensure that your api calls only happen once.
As for a way to transport data back to page1...
You could create a custom model that page1 relies on, and inject that model to other pages
You could use the delegation pattern to pass back information
You could use notifications and observers to broadcast and catch updates
You could pass a reference of page1 to any other page and allow other pages to make updates to page1 on its behalf
All 4 strategies are viable, and really depends on your use case and what other things you need in your app. You could even use a singleton. UserDefaults seems like a bad idea though, since your use case is to update a model for a view controller.
I have a simple app in Swift with just a few views:
A UIWebView
some TableViews
and another view with some data I download from my server
It all works well until when using the app I press the home button, leave there for a while then the iPad goes on sleep mode. A few days later I tap on the app icon and it won't start:
first tap on the icon will select the icon (goes a little darker) and deselect it a few seconds later
second tap will launch the LaunchScreen and crash a few seconds later
double tap the home button and quit the app will sometimes work
I'm just wondering if there is something I need to set on my code to handle idle/long periods of inactivity in something like viewWillDisappear or other methods?
If so I already have this in all my controllers:
override func viewWillDisappear(animated: Bool) {
timer.invalidate()
webView.removeFromSuperview()
}
Maybe I need to call super. in there too? or something else I'm missing?
You should definitely call super in your viewWillDisappear(animated:) method. See UIViewController Class Reference documentation. Also you might want to confirm why you are removing your webView from the view controller's hierarchy.
Discussion
This method is called in response to a view being removed
from a view hierarchy. This method is called before the view is
actually removed and before any animations are configured.
Subclasses can override this method and use it to commit editing
changes, resign the first responder status of the view, or perform
other relevant tasks. For example, you might use this method to revert
changes to the orientation or style of the status bar that were made
in the viewDidDisappear: method when the view was first presented. If
you override this method, you must call super at some point in your
implementation.
You probably have some null pointer exception and crash. Maybe you are calling some variable that is not set (and checked if not null).
Try disabling app funcionality (like downloading, storing and using data from server) and see where you app starts working normal again and then procede from there.
Sorry for vague answer but withouth code and maybe some log it is really hard to give specific answer.
And NO, you dont have to do anything special to handle idle/long periods of inactivity.
I have a virtual function called DoRotate() that does an animation of a subview rotating. Pretty simple... It is fired from a timer event, and is always invoked on the main thread.
This works like a charm...
Now, I sub-class the whole view, and create another view that tries to do the same thing. It is displayed as a sub-view (full screen) of the main view... Now, UIView.Animate() is a No-op.. It never executes the code inside the block at all. It is actually the EXACT same function that is being called in the other view... It is attempting to animate a sub view (a sub-sub-view of the original view...
But it is like the OS is just saying "too bad, so sad, we are not going to work anymore.." - which is typical of the OS,but that is another topic...
Originally, I tried to just make this view another view that would flip over to from the base view, but apparently, without a navigation controller it won't work, and if you have one then the popup menu that I created will no longer popup...
UIView.Animate (tm, 0, UIViewAnimationOptions.CurveLinear, () =>
{
MapRotating = true;
_DoRotate ();
},
() => {
MapRotating = false;});
}
The MapRotating = true; never gets called.. I've put this before the animate call, but then it never tries again if the animate fails... This way, it keeps failing forever...
_DoRotate computes the angle to rotate and rotates it (sets a transform)...
Is there a UIView.LastError() method that I can call for it to tell me WHY is it Ignoring my request... (ooh, how about throwing an exception if we passed it something it didn't like?)
-Chris