The app in question is a simple sample program. In my view controller header, I have the button instantiated as such:
#interface ObscurelyNamedViewController : UIViewController {
UIButton *yoButton;
}
#property(nonatomic, retain) IBOutlet UIButton *yoButton;
- (IBAction)yoButtonPressed:(id)sender;
yoButtonPressed: is implemented as such:
[yoButton setTitle: #"I said 'yo', jammit!" forState: UIControlStateNormal];
// repeat for other button states
.
.
.
In Interface Builder, I have connected the Touch Up Inside event of the UIButton to the yoButtonPressed method in the File's Owner of the ObscurelyNamedViewController to recognize the touch. In return, I have connected the outlet of the File's Owner back to the yoButton, so as to enable the updating of it's title.
When I build and run, I get no errors, but nothing displays and the app immediately quits. The only other thing living in IB is a UIImage view. Am I missing something or have I wired something incorrectly?
EDIT: In the console, I see the following message:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "BradiiCaliiViewController" nib but the view outlet was not set.'
This likely has nothing to do with that action. You said, "nothing displays and the app immediately quits", which means that the action was never sent.
Need your message from the Console, but check
Did you use initWithNibName? If so, did you get the name exactly right?
Are you doing anything with Outlets in init? You should not -- and do it in viewDidLoad.
Knowing the message in your console will help us give you the real answer though.
Edit: based on your console message
Double-click .xib file to go to IB
Click on File's Owner
Go to Connections Inspector
The view outlet is not set (right?) -- drag the circle to the view icon in the Document Window.
(I am sorry, but I don't have IB in front of me -- this is from memory -- look around for the view outlet in connection inspectors if I am wrong about the exact location)
Moved from comment on Lou Franco answer:
BradiiCaliiViewController complains that it doesn't have a view even after NIB was loaded. You have to connect view outlet of File's Owner to your view in BradiiCaliiViewController's XIB.
Related
Hello I have this warning.
how can I solved this ?
Main.storyboard: warning: Unsupported Configuration: Scene is unreachable due to lack of entry points and does not have an identifier for runtime access via -instantiateViewControllerWithIdentifier:.
In the Storyboard, select the view controller you want to load when the app launches, and make sure to select the "Is Initial View Controller" checkbox on the right.
This warning is comes up if an unconnected view controller exists in a scene. In the image below for example I have disconnected a segue from the button to the small view controller below it to cause the warning. During development this can be ignored as long as you keep track of the VCs you disconnected.
In the image below the warning is gone because the small view controller is now "connected" via segue.
for some more information:
Any project consists of two classes, AppDelegate and ViewController.
If you open AppDelegate class you can see UIApplicationMain.
The #UIApplicationMain attribute at the top of the file designates the AppDelegate class as the entry point for the module.It is a requirement for using storyboards that your application delegate inherits from UIResponder and that it has a UIWindow property.
it is done in info.plist.
“Main storyboard file base name” specify the name of the storyboard that must be loaded when the app starts.
The arrow pointing at the view controller from the left indicates that it is the initial view controller to be displayed for this storyboard.
sometimes when you build you get error like "failed to load: entry point not set". it is clear that you not set an entry point, meaning you not set initial view controller to load.
To fix this just open Attribute inspector. Check the box : is initial view controller.
Even you can verify for some more details:
https://www.raywenderlich.com/113388/storyboards-tutorial-in-ios-9-part-1
All of the topics that I have searched are outdated or not complete in Obj-c.
I need to learn how to change a button's background image programmatically, when having the actual button in the InterfaceBuilder. (This sounds odd, but I need it for NSCollectionView as I have many similar button with different background images).
In the interface builder I drag a button onto my view window, what should I do after?
I understand that:
I need to create a NSButton Class
Connect the button from the interface builder to the code
Set the image
I have been struggling with this.
So did you connect the button to an IBOutlet property? If so then all you need to do is use [button setImage:]
If you haven't already done so, make sure the object instance that you want to change the image from is in interface builder, I.e has been dropped in as one of those blue boxes. Then if you set the object's class and have an IBOutlet property in the header file you can just drag the button outlet in the outlets tab (looks like an arrow) to the actual button itself to link the two
Edit: So it appears you're having trouble with the actual connecting part of the button? Chances are your IB file looks a bit like this:
Look for the objects section in the left hand list. These are the actual objects in your code that you can connect your button to. You might see an app delegate object there, which is included in the default IB file generated when you first create a project. If you want to handle the image changing in your app delegate, then simply add this property to your AppDelegate.h file to create an outlet:
#property IBOutlet NSButton *button;
If you go back to interface builder and select the app delegate object, you can see the outlet that you just created under the outlet tab:
Drag the little circle thing to the button to connect it, that should be the easiest bit.
But I'm going to just presume that you want to call it from somewhere else other than your app delegate, and for that we'll need to do some more explaining. If the class you want to call it from is a subclass of NSView and is already in your interface builder, you can just add that line to your view's header file and it will appear under the view's outlet tab.
If you want to call this from another object that isn't a view or such, you'll need to do either two options:
Create the object instance in interface builder. This means that instead of creating in normally with alloc] init]; etc. you'll have to actually drag in an object into interface builder. This can change the structure of your object quite a bit as you'll no longer be able to create it at will, since it will automatically be instantiated whenever you load your .nib file. Also important to note is that your init function will not be called anymore and you'll need to use awakeFromNib instead. If you do choose to go down this route, just drag over an object:
Add your outlet property to the header file:
Set the object's class:
And connect the outlet:
If making objects XIB loaded just isn't your thing, you can always just connect the property outlet to your app delegate/view controller and access it from that instead. Hopefully this clears things up, if this was the problem you were having.
For iOS:
Don't need to create a NSButton subclass.
You only need to add button on Storyboard, set the IBOutlet property for your button (ctr+drag from your button to your view controller), and set the background image with:
[myButton setBackgroundImage:[UIImage imageNamed:#"ImageName"] forState:UIControlStateNormal]
For MacOS:
You can use
setImage:
as describe on Apple Doc, and changes its size/position
(Sorry for my bad English)
ofcourse as Duukee Said,i think no need to create any NSButton Or UIButton Instances Manually When We have an object in Interface Builder,We can just use it's outlet as follows,
UIImage* Desired_Image=[UIImage imageNamed:#"yourimage.png"];
[My_Button setimage:Desired_Image forState:UIcontrolstateNormal];
HTH!Happy Coding :)
I would like to link an imageView and a textField in my xib grafical user interface to the belonging Outlets from the NSCollectionViewItem (which is an element from the application kit). But while linking the bindings following message pops up:
"Xcode cannont find a Key Value Coding compliant property named #property (assign) IBOutlet NSImageView *imageView NS_AVAILABLE_MAC(10_7); in the class NSCollectionViewItem."
So, for me it is not possible to connect these objects. Therefore I don't get any Referencing Outlets for the Text Field or the Image View.
In an another xib the same bindings exist already. But they are marked with a white exclamation point and also show up a strange message: "NSCollectionViewItem does not have an outlet named imageView."
Does anyone knows how to solve the problem? Would be great.
I just tested this and can confirm, regardless of the NIB's deployment target. It seems like an Xcode bug.
I created a custom subclass of NSCollectionViewItem with no actual customizations. I set the class of the collection view item in the NIB to my custom subclass and the outlets were suddenly available. I then set the class back and they were still available. I connected one and built and got no warnings or errors.
I have a class called ActorController and it has a NIB file. I have created IBOutlets in ActorController.h that match up with various UIViews and UIImageViews in the NIB file. However, these views never show up on the screen like they should. Upon further investigation, I have discovered that if i use NSLog to print the UIView object to the console, it prints null. Could anybody suggest what I may be doing wrong? Any help is appreciated.
Some things to look for:
Nib not loading at all:
wrong name
nib file not included in project
capitalization problems (iOS is case-sensitive on the device)
outlets not connected (views should still show up on screen, though)
outlets connected, but to wrong object
view controller created and initialized properly, but not displayed
active view controller is not the one you initialized from the nib
I so far only have the interface builder layout
I'm not clear on the syntax to reference all of these items from the layout
I know that IBOutlet has to be used somewhere, but I need a bit more handholding on what this objective C is doing. Nothing I've read tells me exactly why some declarations start with + and others with -
What I want to do is click a button in my layout, have a modal view pop up and change the background on the entire layout.
so the first step is referencing all these items I've made in the nib. help? (or post a link to more intuitive tutorials that you know about)
So you probably want to create an IBOutlet for your background view. Maybe it's a UIImageView that you can set it's image property based on what the user selects in the modal view. For this you would just declare the UIImageView you have in your IB file
UIImageView *imageView;
and then declare it as a property
#property (nonatomic,retain)IBOutlet UIImageView *imageView;
and synthesize it in your .m file
#synthesize imageView;
Don't forget to release it if you're not using ARC.
Then you can open up interface builder and if you click on your view controller File's Owner and go to the connections inspector you will see there is a new connection there for imageView. Just drag that connection over to your UIImageView in the IB file and that's it. You now have a reference in your code that connects to your UIImageView in IB.
That will allow you to set the UIImageView in your code by typing something like
self.imageView.image = [UIImage imageNamed:theNameTheUserJustPicked];
In order to get the modal view, you need an IBAction to trigger a method in your code so declare one like this in your .h file of your main nib.
- (IBAction)displayViewBackgroundChooser;
and then define it in your .m file.
- (IBAction)displayViewBackgroundChooser {
//present your new view on screen here
}
Then go back to interface builder and click on the File's Owner again. You should see it there in the connections inspector and then you can connect it to a button, for example, that would trigger that method.
Hope this helps to clear things up a bit on IBOutlets and IBActions.
You can make your UI elements created in IB interact with your code by means of IBOutlets and IBActions.
In your case, I would associate an action to the button, so that it is fired when the button is clicked; the action would open a modal view, and you could change the background of that view in the viewDidLoad method of the associated controller.
Here you find a video tutorial about adding an outlet. And here, the same about actions.
About your doubt on + and -, - identifies a normal method defined in a class; + defines a class method, i.e., a method that you can call on the class directly, without having to instantiate it first. Have a look at this S.O. article for more.