Ive got this code and everything works correctly. But when I'm testing my app the switch is really hard to turn over on the UI.
-(IBAction)mySwitch:(UISwitch *)sender {
if([_theSwitch isOn]){
[_theSwitch setOn:NO animated:YES];
}
else if (![_theSwitch isOn]) {
[_theSwitch setOn:YES animated:YES];
}
}
is there any way that I can make it like the iOS 7 settings switches where it toggles on and off by button press rather than slide?
The reason is the code you've added. There is no reason to tell the switch which state it is in. It knows that info already. Remove all of that code and it should solve the issue.
Related
I have no idea where to even start trying to fix this but maybe someone can point me in the right direction. I have a status item application that shows a popover when clicked, some user interactions produce an NSUserNotification to warn/inform about changes or errors. But when the notification appears it is shown behind the popover, so if they overlay the user can't read what it says.
Is there a way to force the notification to appear in front of the popover? Like order the notification to the front.
Edit: here's a picture showing part of the notification hidden behind the popover after a user gave bad input. I don't really want to hide the popover to show the error notification.
I've tried stuff lake makeKeyAndOrderFront, activateIgnoringOtherApps, the type of stuff you'd use on a window, but none of it applies to an NSUserNotification so it doesn't work.
Edit 2: I should note that to get the popover to appear in front of everything when called I use activateIgnoringOtherApps and becomeFirstResponder on the popover, but even getting rid of that still shows the notification behind the popover.
Edit 3: The popover is shown relative to a status item in the status bar using
[[self popover] showRelativeToRect:statusItem.view.bounds ofView:statusItem.view preferredEdge:NSMaxYEdge];
When clicked, the status item calls a method that does this:
- (void)openPopover:(id)sender {
if (![_popover isShown] | (_popoverIsClosing)) {
[_preferencesWindow close];
[NSApp activateIgnoringOtherApps:YES];
[_popover becomeFirstResponder];
[statusItemView setHighlighted:YES];
[[self popover] showRelativeToRect:statusItem.view.bounds ofView:statusItem.view preferredEdge:NSMaxYEdge];
[self performSelector:#selector(defaultTextField)];
NSLog(#"popover opened");
} else {
[_preferencesWindow close];
[NSApp activateIgnoringOtherApps:NO];
NSLog(#"popover closed");
[_popover close];
[_popover resignFirstResponder];
[[NSApplication sharedApplication] hide: self];
[statusItemView setHighlighted:NO];
}
}
Thanks for the help.
You want to adjust the window.level.
A notification is using level 18, so as long as your level is lower, you will not have this issue.
You can use these default NSWindow.Level
.normal = 0
.floating = 3
.submenu = 3
.tornOffMenu = 3
Or a custom level NSWindow.Level(rawValue: 17).
An important thing to note is you should set the windows level during or after the popover did show. Otherwise your setting will be reset.
You can do this from the popover.delegate using the function,
func popoverDidShow(_ notification: Notification)
Or listen to the notification directly with NSPopoverDidShowNotification.
This has been tested on macOS 10.15
I am using phonegap version 2.2.0 and have installed ChildBrowser plugin code to XCode project, plugin loads fine with no problem. When navigating to a static html page in the main view which has bunch of tags and each tag has link to external page. Once you click that external link the ChildBrowser loads as expected, but when I close the ChildBrowser by clicking "Done" button the original view is there as expected. but when you try to scroll in that main view the scrolling part quits working, I am no longer able to scroll that page? I added following [[self parentViewController] reloadInputViews] line and thought that may solve the issue, but the problem still remains. Also, it whacks out the original stlye meaning the buttons and font looks larger. Some how the original webview needs to maintain it correct state. Please suggest any corrections.
I was looking at the close button event code
\Plugins\ChildBrowserViewController.m
- (void)closeBrowser
{
if (self.delegate != nil) {
[self.delegate onClose];
}
if ([self respondsToSelector:#selector(presentingViewController)]) {
// Reference UIViewController.h Line:179 for update to iOS 5 difference - #RandyMcMillan
[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil];
} else {
[[self parentViewController] dismissModalViewControllerAnimated:YES];
[[self parentViewController] reloadInputViews];
}
}
I've been making an app that I need help with. After I do what I want the app to do, it goes to a new page. when I press the go back button, it is still in the same state as when I left. I want the first view to completely reset when I hit the button. Any suggestions as to how to do this? Any help is appreciated!
Here is code for what the button currently does:
- (IBAction)retry:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
}
Implement viewWillAppear on your initially displayed viewController as following:
- (void)viewWillAppear:(BOOL)animated
{
//
//put your code to reset this viewController into its initial state here
//
[self resetAllStatesBackToDefault];
}
As an example, suppose you got a UITextField on that first viewController that is named textField;
- (void)resetAllStatesBackToDefault
{
self.textField.text = #"";
}
What you need is the -(void)viewDidAppear:(BOOL)animated;
I am developing an application were everything is working fine, except one i.e. when user press on home while keyboard is in active and again opens my application the view frame bounds are changing and moving out of bounds. My expected result is keyboard should get suspended or the view should stay in the same position when it is come back from background to foreground with keyboard in-active state.
I hope people understand my scenario and reply ASAP.
Thanks.
I have found the solution to my question, i hope people can use my solution. Below is the code what I have done,
Add the below line of code in your RootViewController file (i.e. which view is coming at first when you open your APP).
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(receivedNotification:) name:UIApplicationDidEnterBackgroundNotification object:nil];
And then add a private method as below
- (void) receivedNotification:(NSNotification *) notification
{
if ([username isFirstResponder])
{
[username resignFirstResponder];
}
else if ([password isFirstResponder])
{
[password resignFirstResponder];
}
}
I hope it help some body,Thank u.
Further assistance please see the mentioned link,
there is a method in the app delegate
- (void)applicationDidEnterBackground:(UIApplication *)application
this method is fired when you press the home button.
do the necessary changes(textField resignFirstResponder) in this method and it should work fine i guess.
EDIT here's the code
in the class where you have your textfield create a method
-(void)performWhenHomeBtnprssed
{
[MytextField resignFirstResponder];
}
then in
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[myClassObj performWhenHomeBtnprssed];
}
also i agree with #valexa you should find the root cause of the problem
In software development it is always better to address the root causes than to patch the effect, in your case there are problems with the positioning of your views and you should address that, foreground/background cycling should not affect the views positioning.
I am trying to present a modal view in a tabbar app. I am using the code
- (IBAction)newView
{
[self.viewController presentModalViewController:viewController
animated:YES];
}
linked to a button. When the button is pressed, nothing happens and nothing is displayed on the log. This is most likely simple to fix, but I have not found anything that has worked yet.
Thanks
Use this and you rock:
[self presentModalViewController:viewController animated:YES];