i have got a page in QML and i have implemented a new logic (function back()) for back button on this page. now I want, that this logic would also run after swiping the page from the screen. What is the best way to do it? onPeekEnded event is not suitable for this situation, because it fires also when the swiping was canceled. Thanks.
paneProperties: NavigationPaneProperties {
backButton: ActionItem {
onTriggered: {
back();
}
}
}
When you push a new page to the screen using a NavigationPane, a onPopTransitionEnded() signal is fired after the page is dismissed, either by the back button or because the user swiped it away. You can add a slot for that signal to your controller, and put your logic there.
There is no need to implement manual back button functionality here. You get all of that for free.
Related
I want to build some analytics into my app and I would like to send some data when user leaves current screen, though there are multiple ways he can do so (back button, other button, sidebar menu, etc). Is there any efficient way to do this? I really don't feel like implementing it to every possible button that can lead the user to different screen.
You should call your function inside viewWillDisappear, which is called every time the current view controller is about to disappear from screen. See the documentation of viewWillDisappear
Also see the view controller life cycle (thanks #Paolo for the tip) below (documentation).
So in this game, i have a button pop up for a short amount of time. If the button disappears before the user clicks it, then they lose the game. How can i make it so to check if the button has appeared and they have not clicked it during its duration of appearance they lose the game. I already have all my necessary functions for when the game is lost. All i need help with is how to read if a user did not click a button during its time of appearance.
#IBAction func tapButton(_ sender: Any) {
if colorImage.image == UIImage(named: "\(self.currentColorNumber).png") {
// give the user a point
}
So i am able to give them a point if they tap the button. How do i end the game if they do not tap the button?
Wow hold on just a minute of algorithmization. Why dont you detect the user didn't tap the button on the button disappearance? If the user cliecked the button, the action happens, some class bool gets true and something happens... that's fine as it is. If the user didn't, you listen to the point the button disappears and handle the custom action there. I don't see anything hard about that.
Whenever I swipe the page controller and tap the UIPageControl at the bottom in the opposite direction of the swipe at the same time, the page that is currently being displayed and the page number in the pageControl will be out of sync.
Has anyone ever had this weird issue and solved it?
Let me know if you need any additional info.
Just checked out the docs for UIPageControl. I never realized this myself, but you can use page controls for input:
When a user taps a page control to move to the next or previous page,
the control sends the UIControlEventValueChanged event for handling by
the delegate. The delegate can then evaluate the currentPage property
to determine the page to display. The page control advances only one
page in either direction.
My suggestion would be to either disable the page control or update your app to respond to input on it. Setting userInteractionEnabled to false on my page control resolved the problem for me.
I'm writing a simple iOS 6.1 game. The game involves pressing buttons (OK, it's a tictactoe board, with the cells being UIButtons). The allows the player to choose whether to go first, or whether the computer should go first. If the player tells the computer to go first, I want to set some values, and then fire off the UIButton just as if the user had pressed it.
How can I post an event, or otherwise simulate the action of the button being pressed, to let the rest of the framework do the work of handling the button press?
If there is a better design approach, where I don't have to pretend that the computer has pressed a button, I'm open to hearing about that, instead.
Thank you
Your button will be connected to an action method, typically in your view controller. Just call that method yourself, passing the button as the sender.
Your method will be something like:
-(IBAction)buttonPressed:(UIButton*)sender
{
// Respond to your button press...
}
You'd call it as follows:
[self buttonPressed:self.whicheverButtonYouLike];
You'd need the buttons defined as outlets for this to work.
I have a form on a tabbed view; I mark the form dirty of any of the fields have been changed and I want to pop up an ActionSheet with "save"/"cancel" if the form is dirty (in lieu of a "save" button). Is there any way to stop the view from disappearing (or being removed from the view stack) until the user responds to the ActionSheet being handled?
A couple of thoughts:
It's worth noting that Apple's Human Interface Guidelines (the HIG) explicitly discourages this practice. They suggest that apps should "ask people to save only when necessary" because people "should have confidence that their work is always preserved unless they explicitly cancel or delete it." Perhaps in your case, it's important to have this feature, but it's generally discouraged.
An alternative, if you want to give users the chance to revert to old settings is to provide an "undo" button, that way, you honor the HIG and effectively auto-save, but you also give the user to explicitly revert to prior values if they really need to.
As others have noted, the notion of prompting to save or discard on viewWillDisappear doesn't quite work. It's logically too late in the process. viewWillDisappear could be called for too many reasons, many of which are not under your control, and it's not copacetic to fail to return promptly to that method, to introduce new user interface elements, etc.
If you really, really need the "save" vs. "cancel" user interface, then that lends itself to more of a modal interface (or push a new view controller that you have to pop off to return to your tab bar view controller) with save and cancel buttons rather than a tab bar interface. E.g. your tab bar view could show current values, you tap on an "edit" button, which pushes new view with save and cancel buttons. We don't know enough about your app to be able to advise whether this is logical in your case or not. (For another approach, see enabling edit mode in view controller.)
You can't stop the view from disappearing once the app has progressed to the point where viewWillDisappear: has been called. The thing to do would be to create a function like:
- (void)saveAndClose {
//Display sheet asking user what they want to do
}
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
{
if (buttonIndex == 0) // 0 or whatever the index of your save button is
{
// Perform save functions
}
[self dismissModalViewControllerAnimated:YES]; // or pop the view controller if appropriate
}