I'm trying to follow these instructions with Xcode 4, but am unable to resize the xib. Does anyone know how? ( The width and height cannot be clicked upon ) Also there is no UITableViewController so I just used UIViewController.
EDIT - My goal is actually not to use the popover controller, I simply want to create a modal login dialog following the example here: How to resize a UIModalPresentationFormSheet? and am trying to make the view controller 300x400
A popover controller has to have a
view controller inside of it. So we
need to create a new view controller.
Go to File > New File > Cocoa Touch
Classes > UIViewController >
UITableViewController subclass >> With
XIB for UI >> Targeted for iPad. Name
it OptionsViewController. Drag your
viewcontroller.h and viewcontroller.m
files into the classes group and the
new XIB into the resources group.
Open the XIB and go to the Size
inspector. Change the width and height
properties to 250 and 300. Save your
file and close interface builder.
It appears that in Xcode 4.5+, just to be annoying: Apple changed this again.
Instead, you now have to:
select the viewcontroler
select the "size" dropdown
set it to "Freeform"
...which removes their "block" on editing the size fields.
(this is pretty close to how I expected it to work in the first place, but I have to say it's not easy to find - you have to edit a different value on a different screen (with no help from Apple), in order to un-break the edit field on the correct screen. Not good design!)
Interface Builder (and the IB equivalent in Xcode 4) won't let you change the size (or autosizing attributes) of a top-level view when any Simulated User Interface Elements are enabled.
Select your view, and in the View Attributes inspector set Status Bar, Top Bar, and Bottom Bar to Unspecified. You should then be able to change the size.
In swift 4.2 interface builder won't let you change the size
click on the view and open the attribute inspector and change top, bottom bar to none and size to freeform. Now you are good to go for the change in size.
Related
I am working to create a custom view for an iPhone app I'm creating. This custom view is a Popover dialog which is made up of a UIView which contains two images, a button to close the dialog, a label, and a UIScrollView. This view is named MDPopoverCard. I have these files as a part of my view:
MDPopoverCard.xib - The view as drawn up in Interface Builder.
MDPopoverCard.h - Defines a few IBActions and some other properties
MDPopoverCard.m - Implements some functions defined in the header
This is what it looks like in Interface Builder: http://cl.ly/2B0f2x3s1w1i0K2G0Q1r (sorry, I can't post an image yet as I'm new to stackoverflow)
There are a few properties defined in my .m and .h files that control whether the green button is displayed and what the text of the title label is.
I need to display a number of these dialogs in my app and I'd like to reuse this interface I've designed. I want to be able to add buttons and other form elements into the UIScrollView via Interface Builder. However, I have a problem:
Imagine that I have another view I'm drawing up in Interface Builder. I add a UIView to it and set its class to MDPopoverCard. I then drag a couple UIButton objects into my MDPopoverCard view. Here's an example of what it looks like in Interface Builder:
http://cl.ly/1X090h1t1q3f0i3E0917
This screenshot shows another view (the root view) that I've added my MDPopoverCard to. I've then added two buttons as subviews of MDPopoverCard.
These buttons do get properly nested in Interface Builder. However, when I run my app these buttons are added before any of the items that make up my MDPopoverCard view in the xib file. This means that the buttons are being added behind my popover dialog. That's the first problem.
The second problem is that I want these buttons and form elements to actually be added into the UIScrollView that's contained within the MDPopoverCard view, and not just right into the UIView's subviews array. Is there a way to specify this in Interface Builder? I'd really much rather draw buttons into my UIView and connect them to IBActions via Interface Builder than hand write every instance of these dialogs that I may need to display (several).
Any advice? Is there anything I can do to clarify the question?
Thanks for your help!
Formerly Xcode supported user-defined IB plugins for custom UI elements which you could just drag and drop into the XIBs the same way you do with built-in widgets. As of Xcode 4 this nice feature has been removed. (Thanks a lot, Apple.)
Currently I can only think of a hacky way to achieve what you described. What I would do is the following:
create an IBOutletCollection on your MDPopoverCard, e.g. embeddedControls
link it with every UI element (here: the buttons) you want to go inside the scroll view
implement the awakeFromNib in MDPopoverCard and explicitly reset the superview of all the views in embeddedControls to the scroll view in there
Hope this helps (although I haven't tried).
I don't understand how to connect elements to a source file. I have a custom UITableViewCell and I want to drag a custom label from it to my CustomCell.h file, but when I drag it over it doesn't do anything..and in storyboards there's no files owner. Is there a short answer to this?
Open the assistant editor (from the toolbar) in xcode (it'll open two views side by side, one view with the xib and the other with the corresponding .h file). control drag from your label to the created property.
Yeh that is pretty weird the way they've done this. As you may know in interface builder you usually drag from files owner TO the element when you want to link to an outlet. It is the same case in this example. So after you've set the class of the cell, in which you have the label. And you've created an IBOutlet UILabel in your CustomCell.h, simply control drag FROM the cell in which you have the label, and you will see your desired option to link it.
I started with a Tab Bar Application. I deleted the SecondViewController.xib and in Interface Builder I deleted the associated tab bar button. Then in XCode I created a SecondViewController and a ThirdViewController. I added two tab bar buttons in IB and made these view controllers the file owners for their respective buttons. Then in the third view I added some UITextFields and a UIButton.
I can run the program, change view, and see the things I made in each of those views. The problem is when I create IBOutlets and IBActions in ThirdViewController and go to IB to link them to the things in the third view, none of those show up, so I can't make the links to the things showing in the view. Why is that?
There might be several reasons, try these ones..
Select the FilesOwner in your interface builder and try Menu > Read Class Files, point it to your Header file(s). See if you can view the IB (Select the FilesOwner / Item -> Menu > Tools > Connections Inspector.
Or You might have unsaved Header files with IBOutlets and IBActions, first try saving those
I'm using Objective-C and Cocoa, whilst developing for Mac OS X - so not the iPhone/Cocoa Touch. (That said, I'd be interested if it was the same procedure for the iPhone)
I'm working on a preferences window for a simple app. I have a NSWindow with a toolbar - there are 5 different items on the toolbar, all of which need to bring up a different set of options.
So I set the NSToolbar and its items in Interface Builder, and then placed a custom view underneath the menu - taking up the rest of the window. My plan is to work out the interface too each of the NSToolbarItems options, and then draw the corresponding view on to the custom view when the specified NSToolbarItem is clicked.
I'm guessing that I simply create a NSView sub-class for each view, an empty xib in Interface Builder - set the xib to my custom NSView, code it as usual... But here's a few problems;
1 - Just how can I get the xib file to appear on the custom-view then? I have looked around and most articles don't seem to have this situation, or a situation I can relate too.
2 - When the window comes up, I want the default view to appear on the custom view. Once again, I'm guessing I just write that in the initialisation code for the NSWindow - its no big deal. It just goes back to question 1 though - how do I draw my NSView to the custom-view specified in Interface Builder?
I'd be really grateful for any help!
Cheers in advance.
So I set the NSToolbar and its items in Interface Builder, and then placed a custom view underneath the menu - taking up the rest of the window.
You can't have a menu inside of a window. You can have a pop-up button, which has a menu, but not a menu directly. Did you mean “toolbar” here?
You don't need to create a custom view for this. Make a tab view and set it to be tabless. Give it as many tab view items as you have toolbar items. In your controller, write an action method for each of the toolbar items, and in each action method, switch the active tab of the tab view.
You can activate different tabs in IB to populate them with views in IB. The active tab is saved in the nib, so make sure you set it back to the first tab before saving, so that the first tab is the one that's initially active when your app runs.
Just how can I get the xib file to appear on the custom-view then?
That question doesn't make sense.
Once again, I'm guessing I just write that in the initialisation code for the NSWindow - its no big deal.
You would only be able to do that if you have your own initialization code for the window, which you would only have if you have subclassed NSWindow. There are very few reasons to do that; unless you're making the window itself look different (not making an Aqua or HUD window), you should move that initialization code elsewhere, probably to the aforementioned controller (which should be the File's Owner of the nib).
It just goes back to question 1 though - how do I draw my NSView to the custom-view specified in Interface Builder?
A custom view in Interface Builder is a plain NSView (unless you explicitly change it to a subclass of NSView you create). However, you do not need one for anything you have described in your question.
I have an .xib file connected to a ViewController, which is init'ed as the root controller of an instance of UINavigationController in my appDelegate.
In that view, I have a UISearchBar and a UITableView below it.
When the view loads up, there's a navigationBar at the top, followed by a ~20 pixel gap, and then the UISearchBar, and the table beneath it:
My problem is that when I enter the UISearchBar to type something, the navigation bar disappears (which is fine), but the search box is all screwy:
I'm pretty new to this (a couple of weeks), so I'm not quite sure what's going on. Can anyone help me shed some light on this?
Did you pull the search bar into the parent view or into the table view? The search bar should be the header view for the table, and not as a standalone view. If you want it to be standalone anyway, make sure your autoresizing flags are correct (under cmd-3 (size) in the inspector in Interface Builder); the search bar should stick to the top and not be flexible in height.