I have a project that I got handed me (half working / half not working) and I have never seen something like to this before.
I have a storyboard and one of the scenes is called 'CompletionVC' and inside that scene I have this:
and in my header file for this scene I have this:
UIPickerViewDataSource,UIAlertViewDelegate>
{
IBOutlet UIButton *areaButton;
IBOutlet UIButton *unitButton;
IBOutlet UIView *searchView;
__weak IBOutlet UILabel *userLabel;
}
and none of those IBOutlets have any Referencing Outlets.
and in my .m file for this scene I have this:
- (IBAction)AreaButtonPressed:(UIButton *)sender
and this does not have a sentEvent assigned to it.
But somehow they are still appearing in my app, which is fine, but I want to adjust them and I cant find them anywhere....based off the information I provided, can someone give me a tip or two about where I these IBOutlets? I would like to make some adjustments, but I can't find them anywhere...also sometimes these IBOutlets have a Sent Event and Referencing Outlet, but it was referencing a file that is not there. The IBOutlets appear and are functional...weird eh?
Related
when I try to create an IBOutlet or an IBAction by linking my interface to the header file, I don't get the option to create one.
Yeah, this COULD be a duplicate but I havent found my answer yet on ANY other post!
Thanks :)
#property (assign) IBOutlet NSWindow *window;
- (IBAction)calculateClicked:(id)sender;
#property (weak) IBOutlet NSTextField *ATextField;
#property (weak) IBOutlet NSTextField *BTextField;
#property (weak) IBOutlet NSTextField *CTextField;
I'm not sure what kind of object you wanted to add your outlets/actions to, but one might infer from the presence of the window reference that you're trying to add that to your app delegate. In that case, you just need to make sure that your app delegate appears in the list of objects, and that you've specified the base class for that app delegate:
If, however, you were using some custom controller object, you would drag an generic object from the library to your NIB's list of objects. Then specify the custom controller class for that object (MyController in my example):
Having done that, when you drag your outlets/actions from the window to the assistant editor, in addition to the app delegate, your custom controller object interface/implementation files will be options that you can use.
My original answer was an iOS-centric answer. The above should describe the Cocoa equivalent. I'll keep this original answer here for reference.
Original answer:
In Interface Builder, make sure to specify the base class for the object you're linking the outlets to. If putting these outlets in a view controller, make sure your storyboard's scene has the view controller's class defined. And it's a little easier if your assistant editor is set to "automatic":
The above screen snapshot is relevant if you're using storyboards. If using NIBs, the idea is the same, but you need to make sure you set the NIB's file owner:
If your IBOutlet references are in a UIView subclass, you analogously have to specify the base class for your storyboard scene's view (or the NIB's view).
I've seen Xcode occasionally do this (bug). Closing/reopening Xcode has fixed it for me before.
Also, make sure that your interface file is Class is pointing to this class/header.
I have created an extremely simple test program. It has one button. Clicking the button brings up an NSPopover with a label. That label is on a separate xib file with its own NSViewController.
The Goal is to, when on the main screen, when I click the button, a popover will show the xib file of the viewcontroller. And the label of the xib file should have it's text set to "It works".
Well.. It works, but only on after the second loading of the popover. On the first click of the button, the label still has its old default value. But from the 2nd click and onwards, "It works". Does any one have an idea what can be causing this issue? Its only about 5 lines of code The code can be seen on this repository --> https://github.com/patchthecode/testtest
Call [mainScreenPopoverViewController view]; in - (void)windowDidLoad method. This will load your view into memory.
Before call [mainScreenPopoverViewController view]; (textfield address is 0x0)
You should not use strong property for all IBOutlet.
#property (nonatomic, strong) IBOutlet NSTextField *textField;
Take a look at Resource Programming Guide
From a practical perspective, in iOS and OS X outlets should be
defined as declared properties. Outlets should generally be weak,
except for those from File’s Owner to top-level objects in a nib file
(or, in iOS, a storyboard scene) which should be strong. Outlets that
you create should therefore typically be weak, because:
Outlets that you create to subviews of a view controller’s view or a
window controller’s window, for example, are arbitrary references
between objects that do not imply ownership.
The strong outlets are frequently specified by framework classes (for example,
UIViewController’s view outlet, or NSWindowController’s window
outlet).
I created 2 View Controllers: on the first I created a button when click on it you will open another View Controller with button and label. I already created outlet and variable for them.
My question is: when I'm trying to connect the button\label with variable\outlet I can't see selection around the button\label -> I mean that I can't connect them all. Why?
P.S. DON'T PUT A MINUS I JUST NEW PROGRAMMER!
Can you post your IBOutlet declarations?
You have to declare UIButtons like this to make them work (connect) in Interface Builder :
#property (nonatomic, strong) IBOutlet UIButton *aButton;
For a label its just the same :
#property (nonatomic, strong) IBOutlet UILabel *aLabel;
I think you have either forgotten to write IBOutlet or your variable type is wrong.
Ok! I resolved the task.
I just needed to create a new Objective-C class, select that new class in Identity Inspector of the second View Controller and write all code in that new class.
I missed this one too.
For anyone still confused, select the View Controller (the yellow box) in your Storyboard and then under Inspector select the Identity Inspector. See images.
Now you will be able to connect up the IBOutlet items in your interface .h file.
Does anyone know a way to, in a storyboard, load a UIView's contents from another nib? I know I can do this easily with code, but I am trying to figure out how to do more in IB.
I have a storyboard with my main UI layout, I have a UIScrollView and I want to design its contents in IB. The only way I could figure out how to do this was to design the UIView in its own .nib, but then my issue is, how do I load the nib without coding it to do so? Is this even possible? It doesn't seem too far fetched to me.
I'm assuming you simply want to lay out your UIScrollView in IB, that a .nib is mentioned because that was an approach you were exploring, but if you could do this strictly in your storyboard that would be acceptable, if not preferable:
First, create a new file in Xcode that is a subclass of UIScrollView.
In your storyboard, drag a UIScrollView out to the scene (viewcontroller) where you want to display this scroll view.
In the Identity inspector, set the Custom Class of the UIScrollView to your subclass of UIScrollView.
Create an outlet for this UIScrollView by ctrl+dragging the UIScrollView into the .h file of the ViewController subclass it's displayed in. Name it something like myScrollView
In your ViewController's -viewDidLoad method, set the contentSize property of the UIScrollView to whatever size you want it to be. So it will look something like:
self.myScrollView.contentSize = CGSizeMake(800,800);
Now, drag out UI objects to your UIScrollView and design.
IMPORTANT: To create outlets to these objects is a little tricky. Let's say you've dragged out a UILabel. You need to manually go into your UIScrollView subclass and add to the .h
#property (nonatomic, weak) IBOutlet UILabel* myLabel;
and to the .m
#synthesize myLabel = _myLabel;
Now you need to get your outline view on screen along with your storyboard and ctrl+drag FROM YOUR SCROLL VIEW TO YOUR LABEL to create an outlet. This is kind of the reverse of what you're used to.
Now you can reference that outlet from within the viewcontroller or the scrollview subclass . For instance, in the viewcontroller -viewDidLoad you could say:
self.scrollView.myLabel.text = #"Hello World";
HTH!
If what you want is to edit inside a scrollview from IB, it's a pain, but doable.
Have a look at my answer on this question.
Add a generic UIView in the IB, setting its custom class to the name of your nib file.
Replace GradientControl with the name of your nib file (minus the '.xib').
Can anyone describe how it is possible to have a TableViewController with its xib file having a at its root and the uitableview as a subview?
I believe the TVController somehow assumes that UITableView will fill the entire area.
Why is that?
I have a really specific need to build a kind of side and bottom tabbed interface with a UITableView as its main area. Pressing tabs changes the predicate for the fetchedresultscontroller etc etc.
The reason I want this is because of the breadth and depth of the data categories in the data model. I rally need to flatten the menu structure a lot...other wise with a table and navbar controller structure, user experience will be akin to sinking to ever deeper depths of a cavern!
My idea is tried and true in other paradigms...in iOS it almost looks like it's Apple's way or the highway. I am OK with APPLE of course no gripe.
But I really would like to create this.
I tried adding a new tableviewcontroller complete with xib and then removing the UITableView in IB and replacing with a UIView and a UITableView as a subview, hooking up (I believe) the delegate to the file's owner.
I created an IV tableView for when I want to reference it and again used IB to hook it up in IB
Try to run it and it whines that...
[UITableViewController loadView] loaded the "TabbedTableController" nib but didn't get a UITableView.'
Really can't seem to get my head around what the issue is here.
There doesn't appear to be anymore I can do to hook the UITableView up!
Any help would be terrific. I'll send you a Christmas card in desperation :^)
Also...why should it be so and how strict is this UITableView fullscreen thing?
Enlighten me if you can. The docs I have read don't want to.
Regards
Keith
A UITableViewController does assume that the root view (i.e. the controller's view property) will be a UITableView, thus the table view fills the screen. When you need a view that combines UITableView with other top level views, you will need to do a little more work but it's not hard:
Your view controller will not subclass UITableView. Instead, do this:
#interface MyViewController : UIViewController
<UITableViewDelegate, UITableViewDataSource>
#property (nonatomic, weak) IBOutlet UITableView* tableView;
In Interface Builder, drop in a UITableView and whatever other controls you need. The table view can be any size and in any location in the view hierarchy. Also in Interface Builder, ctrl-drag from the table view to your VC and set the delegate and dataSource outlets, and ctrl-drag from your VC to the table view to set the tableView outlet.
Your view controller implementation should be the typical table view controller implementation: cellForRowAtIndexPath, etc.
A UITableViewController is more or less just all of the above work packaged up into a single unit for you.