Unable to assign class to image on storyboard - iphone

I have dragged an Image View to my story board, and have created a class called Logo
#import <UIKit/UIKit.h>
#interface Logo : UIView
#property(strong,nonatomic)UIImageView *logo;
-(void)loadLogo;
#end
However, when I try to assign Logo class to my Image View on storyboard in Identity inspector, it does not recognize Logo as a legit class and thus I am unable to assign it. Why is this happening? Logo is a subclass of UIView isn't it? How do I fix this problem?

You have already answered your question. Your problem is because you want to assign your Logo class which is inherited from UIView, with a UIImageView. This won't work.
You have to assign your View with your class under Identity inspector.
Then modify #property(weak,nonatomic) UIImageView IBOutlet *logo; property, and you can assign it.
Add your View into your VC, then assign your View with #interface Logo : UIView, Then modify #property(weak,nonatomic) UIImageView IBOutlet *logo; , Add an UIImageView to your View in Interface Builder, then you can assign your IBOutlet *logo; with the UIImageView what you placed there
If you place a UIView on your ViewController, of corse you can assign it with your custom class only if it is inherited from UIView.
If you place a UIImageView on your ViewController, of corse you can assign it with your custom class only if it is inherited from UIImageView.
and so on...

You have to create an IBOutlet
UIImageView IBOutlet *logo;

1 - Drag a view object from the objects library and add it to a view in your storyboard.
2 - Select it and set its class to be Logo
3 - Add an image view to it
And now you'll be able to assign the image view to be the logo outlet.
If the only way you'll be adding logo is through storyboard then your interface should look like this :
#property (nonatomic, weak) IBOutlet UIImageView *logo;

Related

can't create outlet from storyboard to editor from a subview

Why can't I connect outlets from subviews?
Dropped a UIViewcontroller onto storyboard
Dropped a subview (UIView) as a custom class CustomSubView : UIView
Went into Inspector while subview is selected and changed custom class to CustomSubView
I have a couple of labels inside the subview
I tried to drag-drop from storyboard to assistant editor while CustomSubView class header is shown, but I don't get the pop-up to create the outlet. What gives?
I am using Xcode 5.
You can manually write the IBOutlet property declaration in the #interface of the custom view subclass, and assuming you've defined the base class of your subview in IB, then you can drag from the outlet circle in the code back to the control in the scene.
It was answered here: Cannot create outlet connections to subviews in Interface Builder (Xcode 5)
or you can try this:
After typing the property outlet declarations manually in the customview.h file I could ctrl-drag-connect them from there to their corresponding UIlabel objects in the interfacebuilder. Works only in this direction!

#Synthesize IBOutlet (UIScrollView) not working

This is about an outlet not synthesising correctly (UIScrollView)
In one particular case, i have an interface declared as:
#interface VC_Create_Preview : UIViewController <UIScrollViewDelegate> {
UIScrollView *scrollView;
}
#property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
And in the implementation....
#synthesize scrollView;
But in debug mode i see that my self->scrollView always has a 0x0 next to it.
Performing operations like
CGRect frame = scrollView.frame;
always returns a origin, height, width of zero (i suspect because it did not synthesise correctly)
Does 0x0 mean that it does not point to any location in memory?
Does this mean that it did not synthesize correctly?
Could it be that there is a broken link somewhere from the outlet to the scrollview in IB?
Cheers
Kevin
Make sure that you actually connected a UIScrollView to the outlet.
Keep in mind that scrollView won't be set until after the view has been loaded from the nib.
0x0 means a null pointer, you probably have not tied the scrollView to a scroll view in IB...This means having the viewControllers nib have a scrollView in its view and tied to the outlet.
If you want to work with outlets and use there real size that user will see (include navigation bar, tab bar, etc.) you must implement all UI changes at viewWillAppear or viewDidAppear.
Read more about stages of loading view from nib.
Try removing local declaration of scrollview i.e.
#interface VC_Create_Preview : UIViewController <UIScrollViewDelegate> {
UIScrollView *scrollView;//remove this
}
It may help you. Also while allocating use _scrollView instead of scrollView.
Be sure that you are using the correct class in your code, for example, the first UIViewController you drop into storyboard will have the generic "whateveryourprojectiscalled" UIViewController.
However, the problem for me was that I then had that linked to several other UIViewController, none of which had there own class declared, so the scroller outlet I was writing, is only showing up on the main original UIViewController which is not where I needed it to be. So once I wrote a Custom Class name, and then re wrote the code to accommodate that. The outlet appeared perfectly and worked fine.

Custom UIView from outlet

I know this has been discussed a number of times but I still have some problems getting around the problem, so any help would be appreciated. I have a class MyView which subclasses UIView. So far so good, in this custom class I basically configure the layout, UI, etc.
Now, I have a separate UIViewController and what I want to do is create an outlet for that custom view. In the view controller's Nib I set the view's class to that of my custom view and connect it to the outlet, but I can't see anything apart from a blank view.
How and where do I load the view from nib? Do I simply say self.theOutletForMyCustomView = load from nib or is it something else? Thanks for your help
First of all, you have to set the name of your CustomView inside your UIViewController nib file like that
Then, you have to retain your property like that inside your UIViewController interface :
#property (nonatomic, retain) IBOutlet CustomView *myCustomView;
or an ivar should work, but assign an IBOutlet property doesn't work.
And if you customize your CustomView inside your CustomView class implementation. Beware of doing your initialization in awakeFromNib or initWithCoder: instead of initWithFrame:

Can't update the UILabel from the controller...

I link the xib with the source code, but when I try to update the UILabel, it can't update with no error msg. So, I make a breakpoint. When I inspect to the UILabel, which is a 0x0.
I already made #synthesize in .m, but I created the IBOutlet on the .h, also I did the
IBOutlet UILabel *xxxLabel;
#property (retain, nonatomic) UILabel *xxxLabel;
already.
I can display the Nib and the default value that I set on the IB. But I can't update it from code... ...I do something like this:
MyController *tmpViewController = [[MyController alloc] initWithNibName:#"MyControllerView" bundle:nil];
[cell addSubview:tmpViewController.view];
and I add it to the cell. But the cell only show the default nib view, instead of a updated one.
I tried to update the background color, it successfully update.
What should I do to do so? Thank you.
It sounds like you didn't link the Outlet to your label in Interface builder.
Just control-click your label, drag it to your "File's Owner" (which should have the class set to "MyController") and select your outlet.

How to programmatically alter object created in IB

I've placed an image in my UIView with IB.
How do I move this image around, resize it, etc programmatically? I cannot figure out how to reference it from my code.
Thanks a zillion.
You need to make it an IBOutlet.
So in your viewController, or whatever you are loading from the nib, declare it like this:
IBOUtlet UIImageView *myImageView;
Also, in the actual nib, you must connect the File's Owner object to the UIImageView in your file by right-clicking File's owner and dragging the correct outlet name (in this case, myImageView) onto the correct UIImageView instance in your nib.
Now when you load one of the objects using the nib, myImageView will point to the initialized UIImageView, or whatever else you have.
So if you create an UILabel in Inteface Builder, create an outlet like so in your .h file:
IBOutlet UIlabel* somelabel;
Then hook it up in Interface Builder and then you can access it like so:
somelabel.text = #"something";