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.
Related
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;
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:
I have custom buttons in the nav bar, I want to toggle their state by am confounded by their accessors.
I know to get the button of a view (slightly different code than showed below) or cell I can do this:
mybutton=(UIButton*)[cell.contentView viewWithTag:5];
How can I access the buttons of my navigation bar? (they are already set in code)
cheers
Robert
When you create the button and add it to the navbar instead of releasing the button retain it. Then you can reference them whenever you need to.
So add a property to the view controller:
#property (nonatomic, retain) UIButton *myButton;
Then in the method where you create the button use:
self.myButton = [UIButton ...
Remember to release the myButton in the view controller's dealloc method.
How do I add using the InterfaceBuilder?
If you already have a UINavigationController, it's preferable to use its built-in toolbar.
In Interface Builder, check "Shows Toolbar" in your Navigation Controller's properties, and then use the toolbarItems attribute in your view controllers to populate the toolbar:
self.toolbarItems = [NSArray arrayWithObjects:...];
If you don't have a UINavigationController, you can drag a UIToolbar in from the library. I usually set its frame in the nib using the snap to guides feature. Then you can set the items with the method that #Can Berk Güder gives. Using UIBarButtonSystemItemFlexibleSpace and/or UIBarButtonSystemItemFixedSpace you can get a pretty good arrangement of buttons.
If you're doing it this way, just declare a UIToolbar* toolbar and set #property (nonatomic, retain) IBOutlet UIToolbar* toolbar in the interface of your view controller. In the implementation just #synthesize toolbar;. You can set the items in viewDidLoad and link the toolbar to your nib file by adding a new referencing outlet to 'toolbar' in File's Owner.
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";