Is there any way to clicking a button and opening another .xib file? What I have in mind is that being in a main window I can access another I know it is possible to have two windows in a single .xib file but the times I tried it I didn’t get the result I expected. I hope it was clear here.Thanks Advance!
This wasn’t quite clear, unfortunately; your terminology is off. so let’s clear that up first…
‘xib’ stands (I imagine) for Xcode Interface Builder file. It is an archived representation of user interface objects and their relationships to each other — windows, views, menus, and all the stuff a user sees on the screen — but it’s more like a blueprint. We don’t open an xib file. We load one into our application, and then use its information to create windows, views, and menus that we can show on the screen. When we talk about opening a window, we mean the last two parts of the process, not the first.
An xib file can be set up any way that makes sense for the project you’re doing. It can contain a single window or multiple ones; it can have one view or many; it can have all sorts of support structures (like array or object controllers). When GUI elements share data it usually makes sense to put them together in a single xib; when GUI elements are accessed independently of each other it usually makes sense to put them in separate xibs. But these are pragmatic constraints, not hard-and-fast rules.
So the answer to your question, ultimately, is ‘Yes’, but the details are important. When you click a button do you want your app to:
- Open a window?
- Open a view (like a textfield or a table) and add it to a window’s views?
- Does the new view or window expand on what is already in the button’s window, or does it open an entirely separate function (like, say, a preferences pane)?
As a rule, when I see a phrase like this:
I want to know what result you expected to see, what result you actually saw, and how they were different. I also want to know what precisely you did (did you drag a window object from the library and put it in the xib? did you make any connections or change any attributes of the object?). I don’t need to know everything, but I need to know at least enough for me to mimic what you did on my own machine.
Thanks for clarifying things here Ted,
What I want is the following:
I have a main window containing 4 buttons, “Principal”, “Window1”, “Window2”,“Window3”
by clicking on “Window1” close the main window and go to a new window with other buttons and new features and even for the other buttons, so it could be in a .xib file or a window, so I did an example by hiding objects only for understanding.
I think the option would be 3.
Lol… #3 was a question with two mutually exclusive choices; it wasn’t an option in itself.
But at any rate… Since you’re opening something with entirely new features You have a choice. you can:
- Open a new window, which would be stored in its own xib file.
- Use something like a tabless tab view — basically a tab view in which you’ve hidden the tabs, so that you can switch between tabs programmatically — which means everything would be stored in one xib.
The second - which I recommend in this case - is better if all the views you’re showing are roughly the same importance; it saves you opening and closing windows, which can confuse the user. The first is better if you want to open secondary windows (like utility panels).
In either case, you’re going to want to connect your button’s action to a method in the window’s file-owner, and do the work there.
on buttonClicked:sender
if sender’s title is “Window 1” then
– code here
end if
end buttonClicked:
but I don’t really want to get into specific code until we are clear on a specific implementation.
But I need the previous window to be closed and a new one opened (or loaded), or if not the previous one to be overwritten with the properties of the new opened (or loaded) window.
for example, I have two custom views, the same size for both, view1 has an “open” and “cancel” button, the second view has two “save” and “exit” buttons and of course a main window with the “view1” and “view2” buttons What I want is to click on one of these buttons to close the current view and open (or loaded) the new one.
I think I’m confusing you, I’m sorry if I’m not being clear here
You can do this with a single XML Interface Builder (.XIB) file?
I’m merely having a hard time visualizing what you want to accomplish. I mean, if I understand what you’re saying, it seems like the best layout would be to use a single window and swap out views: basically you’d have a tab view, and clicking a button would open a different tab with a completely different set of UI element within that window. But I don’t know if there’s any hierarchy to these views (which might call for a different layout entirely).
You really should read through the Apple Human Interface Guidelines: https://developer.apple.com/design/human-interface-guidelines/macos/overview/themes/. I’m getting the sense that you don’t quite grasp how to make a user interface that is easy, clean, and functional (which is what users really want from an app). The HIG is a little cheesy, but it will help you settle on an interface that works for your particular needs, and once you have that clear we can talk about implementation.
Hi Ted, I’ll take a look, but if you find a way I can use sidebar with only one .xib file and other views for each window? If yes how could it do?
Hi Ted, I’ll take a look, but if you find a way I can use sidebar with only one .xib file and other views for each window? If yes how could it do?
I think you’re misunderstanding me. We can do this any way you like (within certain restrictions): one xib, several xib, opening windows, swapping views… What I’m concerned about is finding the best/easiest way of doing it. In order for me to guide you, I need to know:
- What you’re trying to accomplish.
- What is important to you in terms of presentation.
I mean, it’s one thing if you ask: “How do I implement this.” That has a clear and direct answer (e.g., I showed you how to implement a sidebar). But what you’re asking for now doesn’t seem to be a simple implementation question. You’re asking how to design your app interface at the xib level, and I can’t do that without knowing what you are designing the app for. If you want to do that by messaging instead of in the public forum, that’s fine, but I cannot help you without more information.
ok, i will send you some more specific information by private message. Thanks!