How can I display a hidden view in Interface Builder which is on a unattached monitor? - macos

I am using Interface Builder to work on NIBs and one of the NIBs must have a view on my external monitor which is not attached because I cannot see it on my MacBook. I have had this problem with editing iPad NIBs which I work on with my larger external monitor.
For some reason Interface Builder is not detecting that there is now just one screen and not pulling this view onto this monitor. There has to be a way to get this back into the visible space so that I can work on it. I have tried double clicking on the view icon in the organizer which normally brings the view forward but it is not coming into view.
What can I do? Is this really a bug that has been around this whole time?

I was seeing this problem as well -- the easiest way to fix it is:
In Interface Builder, double-click on the view object. This would ordinarily bring up the window and give it focus, but in this case it's invisible.
Hit Cmd-W to "close" the invisible window
Double-click the view object again; the window should now re-open onscreen.

Yes - it messes up this way when a XIB is created on a computer with multiple monitors but then later edited on different computer with just one.
To my knowledge the only way to fix is to to open the XIB with a text, or ideally XML, editor and search for negative values in various positioning strings. I've searched for {{-and then changed any negative values found to 0. For example, you'll run across {{-237,172}} When you find the open brace, open brace, minus sign pattern then change the negative value to a zero. i.e. {{-237,172}} becomes {{0,172}}.
When you re-open the XIB in IB you'll then be able to see your views.
To be safe make a copy of the XIB before hand editing.

Try using Exposé to see if the window shows up there. Ordinarily you can use Window > Arrange in Front to rearrange your windows, but it seems the non-document windows in IB don't obey ordinary Cocoa window handling so this command has no effect on them.
I wasn't able to reproduce it myself (when I disconnected my 2nd monitor, the window on it moved to my main monitor), but it may have something to do with the arrangement of your screens. If this turns out to be an IB bug you can reproduce, please file it (bugreport.apple.com).

Not sure if this will work, but open the window from your xib (double-click it) in Interface builder, then go to the "Window Size" section of the inspector. 2 Places might help in there, first the "Initial Position" shows a representation of the window and you might be able to just drag it back to the proper place. Second is "Content Frame". There are "X and Y" settings so try changing them to 0 and see if that does it.

<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>WhatEverYouNamedIT</string>
<string>UIResponder</string>
<string>{{237, 644}, {320, 480}}</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</object
I opened the .xib file with Dashcode and changed the {{237, 644} to {{0, 172} saved and opened with IB and the view "canvas" windows was back on my laptop screen everything else opened up on my external monitor.
THANKS!!!

Related

Ensuring windows are on-screen on OS X Cocoa

Imagine I save my window's position in my preferences file. Now, the user moves the window to a second monitor, then quits my app. Then he disconnects the second monitor and launches my app again.
Now my app wants to restore the window's saved location. But if it blindly restores the old window coordinates, the window will be off-screen.
I used to use ConstrainWindowToScreen for my Carbon app, but now that I'm porting it to Cocoa, I can not find an equivalent for this.
The docs suggest that, somehow, Cocoa would automatically prevent this from happening. While that might be the case when the monitors change while the window is open, in my case where I've stored the window location myself and restore them when I re-open the window at launch, this isn't going to work. I need to invoke Cocoa's magic functionality on demand, but how?
(Note: I am aware that I could iterate over all available screens, but that's quite a pain to write myself if I want to get this foolproof. Still, if you can present a complete C or ObjC function that solve it this way, that'd be appreciated, too.)
See the "Managing Window Frames in User Defaults" section in the NSWindow Class Reference. Those methods ensure that a window will be placed entirely on screen.
If you want to save and restore the window location yourself (as a string), use -stringWithSavedFrame and -setFrameFromString:.
Use -saveFrameUsingName: and -setFrameUsingName to have NSWindow save and restore its frame in the user defaults, given a window name.
I agree with Darren's suggestion to use the built-in mechanism for restoring window positions. Really, it's as easy as setting a window's frame autosave name in IB (or with -setFrameAutosaveName:).
That said, if a window has a title bar, then all of the methods which order it onto the screen (e.g. -orderFront: or -makeKeyAndOrderFront:) will automatically reposition it to make sure at least the title bar and a significant chunk of the window is on the screen. It's honestly difficult to get a titled window to be theoretically visible but actually off-screen.

How to navigate through subviews in Interface Builder

I think I remember reading once there is a way to navigate through the different views in Interface Builder using a keyboard shortcut (in other words select a subview that is underneath another subview by clicking on the view) but I can't seem to find what it is. Does anyone know?
There are commands for jumping between clipped (obscured) objects, but they don't have keyboard shortcuts assigned when Xcode is installed. You can set your own shortcuts in Xcode's Key Bindings preference panel, though:
Since you'll never be editing MacOS X and iOS views in the same file, you can go ahead and assign the same shortcut for corresponding commands in each editor, i.e. use one shortcut for both Jump to Next Object with Clipped Content commands.

trying to make an application can attach and detach a tab from window by drag and drop like google chrome web browser?

I'd like to make an application which user can drag and drop tab to make a new window contains
a tab control user holds. What i am looking for is the exact same functionality of Google
Chrome browser for window and Internet explorer 9. Both Applications create a new window if
if user drags and drop a tab out of original window. and vice versa.
How do i do this? Any advice or sample code will be appreciated
It's not a simple task, but if you work through it bit by bit...
Most tab controls will allow you to detect mousedown (and maybe even drag) and when the cursor is moved away from the tab row, you create a new window with a single tab (and maybe a frame depending on what you want).
When they drop, show the rest of the frame as required.
As for moving the content, this depends on your application layout but it can be as simple as changing the container of a control (SetParent()) or the destination of a render.
You can also just drag an "image" of the tab and only create the window when they drop.
Getting any more detail than this is going to be preety much impossible without specifics (and you actually accept an answer).

IB complains that a new window has contents that go off screen

Interface Builder gives me a warning about the set up of my .xib file.
It says, in a dialog called "MainMenu.xib Info",
Object: Window
ID: 21
Type: Illegal Configuration
Issue: This window's content rectangle does not lie entirely on the screen with the menu bar and may not be completely visible for all screen resolutions and configurations.
I'm using XCode Version 3.1.2 and Interface Builder version 3.1.2 (677). I verified that I could recreate the issue by creating a new Core Data Application and opening the .xib file. Also interesting is that when I open the .xib file, the main window does not display right away (as it does with other templates), but will come up when I double-click on its representation in the window with the File's Owner, First Responder, etc. It has nothing visible in it (it does have a Content View inside it), and the Inspector shows the size as 213 x 107 (px?).
I see that there is a 3.1.3 version out now, and it does look like a bug in either Interface Builder or the template for a Core Data Application, but, is there any way for me to fix this? Resizing the window doesn't help, and it is not at all clear to me under what conditions the errors and warnings come up (ie. if I have to compile, or if they change just as soon as I adjust the UI.)
Easily fixed.
In Interface builder select the window and then from the inspector go to the window size tab and move the window away from the left edge. This will get rid of the warning.

Preferences Window Problem (Once Open And Closed, Will Not Open Again)

The problem I've got is that when the preferences window is opened and then closed, it will not open again. Why is this happening and how can this be fixed?
EDIT: Just noticed also I've got the same problem with Main Window.
The window is being opened via the menu bar and is in a separate NIB file.
It sounds like you forgot to set the 'window' outlet of your window controller (in the Nib, the File's Owner) to point to your window. Once you connect its 'window' outlet the window controller's showWindow: method will work.
Hard to say without seeing the code, but one possibility is that you have "Release When Closed" checked for the window in Interface Builder, and you are loading it once, caching it, then expecting to be able to close and re-open it without loading from the nib again.
For any other noobs like me, having this issue :)
Don't forget to set the file's owner class to be the same as the controller class, then you can connect the 'window' outlet to the panel.
I encountered this same problem while working on the chapter 12 (Nib Files and NSWindowController) exercise in Aaron Hillegass's Cocoa Programming for Mac OS X book. Doug's answer above was the solution - I hadn't linked the window outlet of the Preferences.xib's file owner to the window itself (in this case the Panel (Preferences) window).
I right clicked on the "File's Owner" in the Preferences.xib file then left-mouse-button dragged from the Window outlet to the Panel (Preferences). Once done and rebuilt the application worked as intended. I could close and reopen the custom preference panel and my previous settings were still there (since the preference window is not unloaded just hidden).

Resources