I have a problem where the button's I have added to .xib file are filling the screen when I run the application in the iPhone simulator. In Interfacce Builder, the UI appears exactly as I want it. It is added in Interface Builder, and it is correctly linked to the proper view controller. The button is not being manipulated in the code. Code someone point out some settings to check. This is an error that has been there for a few and days, and I can't seem to fix it.
The view hierarchy is (if this helps):
MainWindow
TabController
FirstView
SecondView
ThirdView
In FirstView.xib, in the document outline under objects, there is a root view, which contains the UIButton in question.
One possibility is that the button is added as the view, instead of a subview of the view. It sometimes happens, when you move a button around -- particularly from within the hierarchy list, it accidentally becomes the view (of the viewController) instead of be a subview.
Most probably is that you have not configured correctly the resizing of the button. You can either set it in code or using the interface builder.
For the interface builder solution select the button and open the "Size Inspector". You will see that there is an autosizing feature, adjust to your need and you are done.
Related
I'm using Xcode 8 and working on a legacy .xib file and need to figure out how to programmatically move all the objects. Questions:
How can I programmatically reference the view (pointed to by the red arrow)?
Assuming I can reference the view, would programmatically moving it also relatively move the four buttons and label contained within it?
Here's a screen shot of the View hierarchy of the .xib file:
Normally, I would just create a UIView object in a separate .xib file with the contents of the view from question #1, and add it the .xib file referenced above but this is existing code and I want to minimize changes if possible.
Assuming you have a view controller for this story board, Option+click your source file to open it in the assistant editor. You CTRL+Drag from the document outline (where your arrow is pointing) to the spot in your source file where you want the outlet to appear and Xcode will create an IBOutlet for the view.
If your question is can you load just the view from the story board without the view controller. I suppose you could instantiate the view controller, take a strong reference to the view, remove the view from its superview and then trash the viewcontroller, but that seems a bit wasteful; in this instance I would copy and paste the view into its own nib.
Note that as far as moving the view, yes it will move all of its subviews. If this is a temporary animation kind of thing consider using the .transform property along with one of the UIView Animation methods. You can also CTRL+Drag the constraints from interface builder and manipulate the constraints in code. You should avoid setting the frame/center manually if you are using constraints otherwise autolayout will be fighting with you.
I am having a hard time understanding why you can put UIViews outside the UIViewController on the storyboard, and what the use case of it might be.
For instance, on the storyboard I can add UIToolbar, UIAcitivtyIndicator and UIProgressView that is outside of the UIViewController. Is this mean there is a way for you to reference those Views that are outside UIViewController and potentially display them somehow either programmatically or embed those like you would do with a ContainerView?
Yes, it absolutely is possible to do what you're describing!
When you add objects that are outside the view controller, they appear in what Apple calls the "Scene Dock". Apple has the following suggested usage for the scene dock:
If a view is not part of the main view hierarchy — such as a pop-up
menu — add the view to the scene dock. In a running app, the system adds
and removes these kind of views from the view hierarchy when they are
opened and closed.
The steps to make this work are below:
Open the storyboard.
Open the utilities area for the workspace window by clicking the
utilities button in the
toolbar.
In the utilities area, select the Object library by clicking the Object Library button in the library bar.
On the storyboard, select the scene to which you will add the extra view.
Drag a view class object from the object library into the the scene dock.
And importantly...
The added view is a part of the view controller. It will be
instantiated along with the rest of the views. You can attach the view
to a property of the view controller that has an IBOutlet. You can add
more than one view to the scene dock.
(These steps were originally copied from here - unfortunately this page seems to have been deleted by Apple at some point).
I created two views in Xcode using the hierarchical view layout. I initially created a button on the first page (PlaylistMasterViewController) which activates the segue method to transition to the next page in the hierarchy (PlaylistDetailViewController), which worked just fine. I then deleted the button, and added a tap gesture to one of the UIImage view elements in the masterViewController and deleted the button. I created the action outlet of the touch gesture to activate the segue and made sure to delete all of the uses of the button in my code, yet this error is thrown once right after the splash screen loads (run time). Any ideas what might be causing this?
In your storyboard check your PlaylistMasterViewController for a connected outlet named showPlaylistDetail with a little while exclamation mark next to it. Then hit the 'x' and clear that outlet connection.
It's most likely some outlet you previously connected and later removed from your code.
The image below is just an example to show you what it would look like.
most common - you have outlet from ViewController to your deleted button in storyboard
You might have deleted the button but something in the view itself may still be referencing it. As the view is loaded at runtime when you try to bring up the view it may have UIButton connected to an outlet that no longer exists.
Open the view in Interface Builder and make all the ui elements in that view are properly wired up and not referencing a non-existent IBOutlet. If there is a problem you'll see a yellow warning icon to indicate a problem.
Just trying to teach myself storyboarding and have run into a question I was hoping people may have an answer to.
I wanted to create a reusable upper toolbar so that in case I ever had to change it, it would update all of my scenes. I created a sized ViewController in my storyboard. I then load it into a subview of each of my scenes using the menu's identifier. THat seems to work pretty well (although, feel free to tell me that's the wrong way to do it).
Here's where the problem starts. On that top toolbar, I have a UIButton which I connect to another sized ViewController in my storyboard as a popover. Basically, a drop down menu. If I just load up the top toolbar, works fine. If I connect just a regular button to that popover scene using a segue, that works too. If, however, I try to click the button and follow the segue while the toolbar is within a subView I crash with EXC_BAD_ACCESS. I presume I'm not allowed to spawn a popOver from a subView or follow a segue within a subview? The latter seems wrong since you effectively do that with any UI object.
How else should I handle this?
Thanks!
I'd recommend using a UINavigationController and setting the toolbar to include your UIButton (as a UIBarButtonItem). If you have any trouble "keeping track" of the toolbar or button you can subclass UINavigationController, add the UIButton (or entire toolbar) as a property of the subclass, and access it from any subsequent view through the self.navigationController property (might violate strict OO, but you could use a protocol).
As for the popover, I think you're OK on iPad but not on iPhone. There are custom projects on github to implement UIPopoverController, and indeed the Facebook app makes use of a custom popover for notifications in their app. iPhone raises an exception if you try to show a UIPopoverController.
I have a view controller on my storyboard set up with a tableview. I want to have another view as a floating view on top of the table view. So, I drag a view (actually a toolbar object) and drop it into the scene dock so that in code I can add it to the subviews and position it so that it floats. I have no questions about the coding; just laying out the view in storyboard.
How do I open the view object that I added to the scene dock so that I can add buttons to it, etc., and design it visually?
I know it's possible since I did it accidentally in another project. The toolbar was in the view controller's scene dock and displayed separately with it's own scene dock. It's very frustrating knowing it can be done, but not knowing how to do it!
(source: bikibird.com)
!
Okay, this is how I did it (also by accident).
I had created an (IBAction) and was trying to connect to a button. So I drug a line from my code to the button (in the list of items). For some reason it wouldn't connect so it seemed to hover over it for a few seconds.
All of a sudden the view (with the button) popped out and displayed next to my uiviewcontroller just like you described. I had done this also by accident, but this is the first time I managed to get it to work for me.
Let me know if this works for you as well!!!
I dont know how to show a view like in your picture, but to design a view visually i put it, for example, as head view on my TableView, design it and put it back to the dock.
It's only a workaround, but that helps me.
All I had to do was drag a UI object (in my case it was a UISlider) from the object explorer on the right into the view I wanted to pop out in the scene explorer on the left