Is it possible to position a view defined in a XIB as a subview in yet another view in that same XIB file? Alternatively, is there a way the "subview" can be defined in another XIB file and positioned in the first view in a different XIB? I've figured out how to do this for UIViewControllers but not for UIViews. Has anyone figured out how to do either of these?
You can view your nib file objects in a tree view and drag and drop one view to be a subview of another.
Related
I have a ViewController, and I want to dynamically load different UIView based on UISegmentedControl.I designed 3 UIViews in xib file. And I have set their File's Owner's Custtom class to my view controller name in Identify Inspector.After I connect my xib to view controller code via IBOutlet, I add the connected view via "addSubview(view)" method in viewDidLoad method. But When I run it, the compiler tells me that the connected view is null.
Instead of making three different xib files. Make one xib file with all three views in it, plus a fourth "default" view. Each view should be connected to a different IBOutlet in your class.
Then in your viewDidLoad figure out which view you want to display and addSubview it to your default view.
I'm just learning iOS programming, so sorry if this is a dumb question.
I have a view in a xib that's acting as an overlay, but I want that view to be "transparent", so that people can manipulate (tap) the views below it. I read that pointsInside:withEvent will do it (if set to return NO), but where do I put this method?
I have a viewController that owns my xib, but putting the method there doesn't do anything...
How do I add my method to a xib view? Do I have to make another view (programmatically) and add my overlay xib as a subview?
Thanks
You can set userInteractionEnabled to NO on the view instead. Overriding pointInside:withEvent: is really for modifying the "shape" of the view.
If you do want to override pointInside:withEvent: you will need to make a UIView subclass and do it there. However you can still add this view inside your xib. Select the view in the xib, and in the Identity Inspector pane set the class to your subclass.
i want to open new xib(view) over the Main xib(view).
i.e Main (Parent) xib when i click on button inside parent XIB. child xib open over parent xiB, and it should see parent xib.
is this possible?
This is probably easiest to solve using viewControllers rather than just xib's (if that is posisble in your scenario). If each XIB is a view with a view controller then the button inside the parent XIB can alloc/init then displayModalViewController which will display the child XIB. As for allowing the child to "see" the parent: in the Model View Controller paradigm, views should not "see" each other - the controllers should update the model from their own views, and visa versa.
I've managed to get my myself confused... I've got a fairly complex View Controller much of which is developed programatically. I'd like to pop up a "dialog" on top of the view controller at some point and I'd like to "design" that view in Interface Builder because it's fairly straightforward (background UIImageView, some UILabels and a UIButton).
I've created the .xib and am now subclassing UIView with the IBOutlets,etc. I'm now trying to wire it up and realizing I probably need to add an initWithNibName: method so this will instantiate correctly...then I realize that I'm really just making another UIViewController and I don't think we're supposed to have UIViewController views w/in other UIViewController views?!?
So now I'm re-thinking how to go about this "correctly." How best to use IB to design a simple 1/4 screen view that will pop up over a main view?
Call +[NSBundle loadNibNamed:owner:] to load the NIB file that contains your view. If you specify your view controller (i.e., self) as the owner, any connections you make to File's Owner in the NIB file will then be made to the view controller. So you could declare an outlet to your custom view in the view controller and after the call
[NSBundle loadNibNamed:#"MyView" owner:self];
the outlet variable will point to the view object. Alternatively, you can use -[NSBundle loadNibNamed:owner:options:], which returns an array of the top-level objects in the NIB.
I'm about at the end of my rope with this freaking project!!!!!!!
I have a UIViewController class that is linked to a nib that has a tabbar controller with 2 tabs. Both tabs load nib files. When I compile I get an error:
-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "MainViewController" nib but the view outlet was not set.
What's going on here? MainViewController views are being populated by nib files (and those files views are linked correctly).MainViewController's Files's Owner has a parameter "view" but shouldnt that be ignored since Im loading both views from a nib? ANY help would be appreciated!
I had the same error (loaded the "xViewController" nib but the view outlet was not set.) in the debugger.
In Interface Builder, I opened the xViewController.xib, right-clicked the View icon, dragged from the circle beside New Referencing Outlet over to the File's Owner icon, then, when the small gray menu appeared, I clicked view. (Then save, rebuild, run, etc...)
I'm not clear on what's going on, but that fixed it.
From what I understand, if anybody wants to follow-up, the View's outlet (which is named "view") was not set, and by dragging the New Referencing Outlet over to the File's Owner icon, I set the View's outlet. Great.
Issue #1 - nib but the view outlet was not set.
1. My MainMenu.xib that had the tabbarcontroller, it's File's owner MUST be connected to some sort of view. So putting in a view object and linking it is fine. I was getting annoyed because it kept showing that file and not the tabbar. #2 solves that problem
Issue #2 - no tabbar being shown
2. Create an IBOutlet UITabBarController and link that to the files owner. And then in the viewdidload method do this self.view = tbController.view; and now your tabbar is being shown not that blank view file you linked to!
You need to add the view from each external nib to the main xib and then connect the view outlet to the correct view. For example, if you have the tab bar in MainMenu.xib and an external xib named ViewOne.xib then open both of them, drag Custom View (or whatever it's called) from the ViewOne.xib window to the MainMenu.xib window. Then connect the view outlet of the tab for that view to Custom View. You should probably rename Custom View once you copy it to MainMenu.xib so that can tell it apart from the other views you will have to add to MainMenu.xib.