I am on objectiveC, OSX, not iOS. XCode 8.3
I have a preferences Window (custom NSWindow) that opens as a modal on my main window.
The preferences window itself contains a view with tabs. The tab height changes the windows size whenever one is clicked.
First Tab clicked:
Second Tab clicked:
Now if someone hides the application in the dock and activates it again, the preferences window becomes active with the height of tab 1, even if tab 2 is still active. So the content gets cut off.
What i need is some kind of notification that gets triggered on becoming active/visible again to trigger a resize of the window before it gets displayed.
I tried it with these notifications in my NSWindow subclass (with NSWindow delegate set).
- (void)windowDidResignMain:(NSNotification*)notification{
NSLog(#"windowDidResignMain");
}
- (void)windowDidResignKey:(NSNotification*)notification{
NSLog(#"windowDidResignKey");
}
- (BOOL)canBecomeKeyWindow{
return YES;
}
- (BOOL)canBecomeMainWindow{
return YES;
}
But none of them worked. Is it because it's a modal window?
Any help appreciated.
I found it. My mistake - my tabViewController triggered a resize on viewWillAppear with always the first tab. I changed that to the current selected tab and that was it.
Related
I'm writing a Mac OS X application using Xcode 6 and Objective C.
After starting the application and press the X, the window will be hidden. Is there a way to show up the window with clicking on the App-Symbol on the dock (like in Safari)?
On clicking "X" or close dot then window closes and if it's a root Window then your app will be closed. So if you want to hide on clicking "X" or close dot then you could use below:-
//Called when clicked close option on window
- (BOOL)applicationShouldTerminateAfterLastWindowClosed: (NSApplication *) theApplication
{
[[NSApplication sharedApplication] hide:self];
return NO;
}
//Called when you tap app icon on dock.
-(BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag{
[[self.mainWindowController window] makeKeyAndOrderFront:self];
return YES;
}
But remember when we hide a OS X app then after a certain time the OS will sleep that app ,called NSAppNap will take place and your background work will be delayed or simply OS will perform those operation in a batching form.
When the user clicks the "X" (or red "Close" dot), that actually fully closes the window and does not hide it.
To make the window reappear (assuming it's still in memory and not released thanks to ARC), you need to do "showWindow" on the window controller. And when clicking on the dock icon, the best place to catch the dock icon being clicked might be NSApplicationDelegate's "applicationDidBecomeActive:" notification.
There are many tabs in my screen,I want to give an alert box which says "Do you want to save the changes?" if user changes anything in the page, without clicking on the save button provided in the page,he is clicking on diff tab.
I'm able to get the alert view but the tab click moves the screen to the tab which was clicked. The screen should not change until the alert view is answered.
Can anyone let me know how to suppress the screen change until the alert view is answered ?
This doesn't directly answer your question, but: what you're trying to do sounds like bad UI design. (In general, if it feels like you are fighting against UIKit, you're probably doing it the wrong.)
In this case: if you really want to ensure that a user taps a Save button before moving to a different screen, you should present that screen in a modal view, so that it is impossible to navigate to any other part of the app.
In other words, if you want to prevent a user from navigating away from a screen, don't show them buttons or tabs that would allow them to navigate away. Otherwise, you're just making more work for yourself and frustrating a user.
Implement UITabBarControllerDelegate in your app delegate's applicationDidFinishLaunching
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
self.tabBarController.delegate = self;
[window addSubview:self.tabBarController.view];
}
Then use the below delegate method,
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController;
This method is called before the tab switch and you can return no here to disable that and show an alert message instead. Once the user has performed the save either he can press on tab again or you can programmatically switch to the new tab as,
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:0];
Add this inside your delegate,
How about this for switching to the tab programmatically,
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if () {
//some code
} else {
//some other code
self.tabBarController.selectedViewController = viewController;
}
}
I think I found a bug in UIKit, but first I want to be sure I'm not insane.
I have a tab bar with a disabled tabBarItem in it. If I present an action sheet from the tab bar, then cancel/press any button in it, after the action sheet dismisses the tab bar item appears enabled, but cannot be clicked.
I want it to stay disabled.
I uploaded an example project here. Run it in the simulator and press the action sheet button on the first view controller. Note the state of the second tab bar item before and after the sheet appears. The project itself is a standard "Tabbed Application" template with one tab item disabled and an IBAction for the button added.
Is this a bug, or am I misusing the APIs?
Looks like a bug it is...
As a quick and safe workaround add this to the view controller (assuming it will be an UIActionSheet's delegate)
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
for (UITabBarItem *item in self.tabBarController.tabBar.items) {
item.enabled = !item.enabled;
item.enabled = !item.enabled;
}
}
I have checked your Project and found a way to make it work. But I don't know actually is it a bug or not. I just find out, it is happening only when you show the actionsheet from the method using showFromTabbar: method.
[sheet showFromTabBar:self.tabBarController.tabBar];
When i changed it to show in this view only, then its not changing the tabBarItem image.
[sheet showInView:self.view];
Hope this could help you to continue to work on that project.
here is the low down:
-(IBAction)button1click:(id)sender;
{
label1.hidden=YES;
textfield1.hidden=YES;
label2.hidden=NO;
textfield2.hidden=NO;
-(IBAction)button2click:(id)sender;
{
label1.hidden=NO;
textfield1.hidden=NO;
label2.hidden=YES;
textfield2.hidden=YES;
the is issue is that when i first open my screen all 4 labels are visible. By default button1 radio is checked but label2 and textfield 2 are visible when they shouldnt be. if i press button1 even though it is already selected the items with hide and then all is good. My issue is having them hidden when the screen first opens up.
Thanx all for you help
You can, in your viewDidLoad method:
-(void) viewDidLoad
{
[super viewDidLoad];
[self button1click:nil]; //nil or the instance of button1 if you need it
}
In this way, you will execute the same code when you press button1 without duplicate your code.
You can take one of two approaches to hide the label.
a) in Interface builder you can click the check box for hidden in the attributes inspector. If you do that the default behavior will always be hidden when the app launches then you can make it visible in code like your example shows
b) add your existing code to hide the label to your view controllers - (void)viewDidLoad method.
both methods work equally well.
When you create that objects you can set foo.isHidden = YES
I made an Mac OS X cocoa app, and when I click the red button the main window disappears.
However, when I clicked the icon in dock, it doesn't show the main window anymore.
What's wrong? How do i redraw the main window by catching what message?
You might be able to do something like this in your application delegate:
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender {
//show your window here
return NO;
}