This seems like a simple thing but I wasn't able to implement it and didn't find information on it.
I have an ionic Loading Controller that initiates when processing some data. This might take time so the user might decide to cancel. So I would like to simply add a cancel button in the loading element which dismisses the loading controller and returns to the previous page.
this.loading = this.loadingCtrl.create({
content: 'Loading ... (cancel button here?)'
});
this.loading.present();
As far s I know it is not supported. I did it with a modal, it works nearly the same and has the same syntax, but you don't have the transparent background.
See: https://www.techiediaries.com/ionic-modals/ for implementation.
Related
I want to pop an alert box every-time after a modal is presented.
I know that I can do something like this modal.present().then(()=>alert("Modal presented"))
However, I have more than 30 pages, which have the modalController.
It is inefficient to add the promise calling to every pages.
Is there any way that I can globally customize the event after a modal box is presented, so that I need not to update all the pages?
You should create a function to show modal in your service. Every you want to show a modal, use that function. So you can handle success callback for every modal presentation.
yourProvider.ts
showModal(component, data) {
this.modalCtrl.create(component, data).present().then(() => {
console.log("show modal success");
//Add your alert here
alert("Modal presented");
}).catch(error => {
console.log("show modal error", error);
});
}
Just call the function above whenever showing a modal:
yourPage.ts
this.yourProvider.showModal("SomePage");
Note that: This is just a suggestion. I did not use this way in real project show can not point out any downside of it.
Check out Lifecycle events, in your case probably ionViewDidEnter().
I have a modal in my Ionic 2 app. In this modal, clicking on a button, a confirmation prompt ("Are you sure?") pops up. By clicking yes, I do certain operations, then dismiss the modal by calling this method:
close() {
this._viewCtrl.dismiss();
}
and _viewCtrl is the property of my class, which i defined this way in the constructor:
constructor(
public _nav: NavController,
public _viewCtrl: ViewController,
public _profile: Profile,
params: NavParams) { ... }
My problem is that behind the modal I have a "3 Tabs Page", sort of. All works well, the 3 tabs are just fine, my modal is ok, it dismisses as it should, the problem is that when the modal is dismissed the 3 tabs break! They freeze on the second tab (which is the one that calls the modal)! Even if I click on tab 1 and 3, I see only the content for tab 2, and I can do nothing.
I'm pretty sure the operations before the dismiss shouldn't be a problem. I found that if I comment out the this.close(); part, and everything goes fine! The modal doesn't close, but I can close it by hand (with the same function, that's the strange thing!) then I return to the tabs page and the tabs are just fine.
What is happening to the app?
PS. No error is shown in the console!
If you check in the console you will see the modal overlay is still there. That's why when you click on any button on your app, you got no reaction cos you click on the transparent overlay.
I had similar issue now, where I had the dismissal of a Modal working before with Ionic 2 Beta 6, but on the latest Beta 10 it isn't working anymore.
How my logic worked was:
Do server call (while displaying progress with the Loading component
When call returns from server, then dismissing the Loading and then the Modal, but calling them in a synchronous fashion
Now this doesn't work with latest Beta. What I had to do was:
this.loading.onDismiss(() => {
this.viewController.dismiss();
});
this.loading.dismiss();
I got this workaround from here:
https://github.com/driftyco/ionic/issues/6325
I'm attempting create a spinning reload button, such as the one found in the new Path app.
It's for a UIWebView, and should behave in the following way:
upon touchupinside, it should reload the webview and spin while it reloads.
while it's spinning, another touchupinside should stop the reloading of the webview.
upon completion of the reload, it should stop spinning
it should be a subview of UINagivationController
Can a kind individual point me in the right direction or link me to a tutorial on something like this? I've searched around and there doesn't seem to be anything similar. Thanks!
The UIActivityIndicator class will give you the functionality you need. Use startAnimating and stopAnimating along with hidesWhenStopped. Documentation is here: http://developer.apple.com/library/IOs/#documentation/UIKit/Reference/UIActivityIndicatorView_Class/Reference/UIActivityIndicatorView.html
To use this with your UIWebView, you can place the calls to the UIActivityIndicator in the UIWebViewDelegate methods.
In webView:shouldStartLoadWithRequest:navigationType: you should return YES, and start the activity indicator. In didFailLoad and didFinishLoad you can then stop the activity indicator.
Finally, for your touchUpInside behaviour, you can send the following messages to your UIWebView, reload and stopLoading.
An alternative would be to call the UIActivityIndicator's methods at the same time as calling reload and stopLoading.
I'm doing an app that uses a TabBarController and each Tab uses its own navigation controller.
The app has dynamic content and I use viewDidDisappear viewDidAppear methods to create or destroy the objects that I need each time I enter or exit into the ViewController.
My problem is when I start to sail very fast and I don't give time to load the Threads that I use for uploading content such as XML peta app or destroy objects when I leave the ViewController.
How I could control the tabs of the navigationbar or tabbarviewcontroller for not respond until the viewcontroller has loaded all contents?
Excuse me if I'm not well expressed. Thanks!
No matter you use synchronous request or asynchronous request, just show an UIAlertView while loading the data. This will both serve as a notification to the user that something is being loaded, and the it will block the interactions with all the other views on the screen.
As others have suggested in comments, I believe that what you want to do is rearrange the order in which things are triggered. Perhaps something like this:
On viewWillAppear:, clear (or disable or whatever is appropriate) your objects that are no longer valid and begin the load-new-content thread. Perhaps display a UIActivityIndicator or similar.
On viewWillDisappear:, tell the load-new-content thread that it can stop, its results are no longer needed. If you put up an activity indicator, take it down.
At the end of the load-new-content thread, take down any activity indicator, update the UI with the new contents and activate.
I don't really see any way around this -- if the UI is not valid until the new content is loaded, then you have to wait for it.
Another solution might be to cache the contents from the previous fetch, and always display those on viewDidLoad. Then, at the end of your new-content-thread, cache the new contents, and update the UI.
I put an in app purchase into my app, and when the user taps a button, the purchase is started. So basically, they tap the button, and then depending on the speed on their Internet connection, they could be waiting for up to ten seconds until a new alert view comes up asking if they would like to buy the product. The user will probably tap the button multiple times since nothing came up, and then multiple purchase alert views will come up. Additionally, this could maybe be seen by the user as an app bug. In the end, this is a problem.
I want an alert view to come up with a spinning wheel that says "Loading..." when the users taps the buy button. Now my problem is, how do I get that to dismiss when the new alert view comes up asking the user if they want to buy the product?
if ([UIAlertView alloc] that says: #"whatever Apple's alert view says")
{
//dismiss the "Loading..." alert view here
}
I doubt that would work, so any input is appreciated. Thanks!
You need to have access to that alertview. You can do this. Create a alertview instance var in app delegate and when you want to show loading initialize that instance var assign to your property and when you want to dismiss just call
[alertViewinstance dismissWithClickedButtonAtIndex:0];
Write this piece of code in a method in appDelegate. Hope you get the idea. If not let me know I'll post the sample code here.