Hide/Show UILabel with hidden property not working - objective-c

I implemented the following code in my CustomViewController's method viewDidLoad to switch a label visibility on/off depending on my needs:
- (void)viewDidLoad
{
[super viewDidLoad];
myLabel.hidden=NO;
if (x==1) {
myLabel.hidden=YES;//here is correctly hidden
}
else {
[self.view bringSubviewToFront:myLabel];
if(!myLabel.hidden){
NSLog(#"I'm not hidden!");// the log displays correctly! so myLabel is not Hidden but I can't see it!
[self.view bringSubviewToFront:myLabel];
}
}
MyLabel is declared in CustomViewController.h ("IBOutlet UILabel *myLabel;") and connected to its corresponding UILabel interface in the Xib file.
Why Can't I see it even if its "hidden"property is false?
P.s the UILabel text is assigned to the UILabel interface in the xib file
thanks
Luca
solved thanks guys I feel stupid.the label was out of the stage so I could see it.I just repositioned it and now it is working fine

You got a typo in your code:
Your outlet seems to be myLabel but your if statement using mylabel (Should be with an Uppercase 'L'). Also note that the getter for this property is isHidden and not hidden as you might expected (this is not the source of the problem though, but Apple stating it in their documentation so I thought it was worth mentioning).
EDIT:
You said:
MyLabel is declared in CustomViewController.h ("IBOutlet UILabel *infoPostRist;") and connected to its corresponding UILabel interface in the Xib file.
So, shouldn't you check infoPostRist instead of myLabel then?

You can try to remove it from the view instead :
[myLabel removeFromSuperview];

Did you try your code in (void)viewWillAppear:(BOOL)animated or - (void)viewDidAppear:(BOOL)animated?
Hiding/Showing views when the view controller is loaded may not work properly.

For the sake of knowledge I answer my own question:the problem was that the label was out of the stage so I couldnt see it.I just repositioned it and now it is working fine

Related

awakeFromNib can't get value from UILabel and can't disable UIButton

I have two buttons in single-view app main storyboard and would like to disable one of them as well as get value from the UILabel using awakeFromNib method. As far as I concern all relationships and GUI items must be initialized and values must be assigned before calling the awake method. Unfortunately I am not able to do get the value and disable button by applying
- (void)awakeFromNib {
decreaseButton.enabled = NO;
decreaseButton.alpha = 0.2;
[polygon initWithNumberOfSides:numberOfSidesLabel.text.integerValue
minimumNumberOfSides:3
maximumNumberOfSides:12];
}
to the class I have made. I have established the connection between the UILabel and
IBOutlet UILabel *numberOfSidesLabel;
in my created class file.
Can somebody see the mistake or shall I provide more info on the problem?
First, you must call [super awakeFromNib]; when you override this method.
Second, standard practice is to use viewDidLoad. Try that instead.

How to prevent a UIButton from changing when touched?

I have a button that pretty much takes an entire xib so that I can push another viewController on the screen if any part of the original view is touched. I've created an IBOutlet to this button and it works great, however I don't want the entire window to turn "blue" when it is touched (similar to when a small button is pressed). I've tried the following two methods that I found in a similar SO post: How can I prevent a UIButton from highlighting when pressed?, but neither method works. Is there something else I need to set up?
- (void)viewDidLoad
{
[super viewDidLoad];
self.entireWindowButton.adjustsImageWhenHighlighted = NO;
[self.entireWindowButton setImage: [self.entireWindowButton imageForState:UIControlStateNormal] forState:UIControlStateHighlighted];
}
I realise this is old question but if you set the UIButtons type to custom then "adjustsImageWhenHighlighted = NO" will work and it is set to NO by default.

UIScrollView not scrolling in xcode 4?

For some reason UIScrollView is not working. It did work before I add the content but after it stop working. I'm stuck can someone help me out!
Here is my code
This is the code for my UIScrollView
#interface EditAccountViewController : UIViewController {
IBOutlet UIScrollView *svScroller;
}
Here is my view Load code
- (void)viewDidLoad
{
[super viewDidLoad];
[svScroller setScrollEnabled:YES];
[svScroller setContentSize:CGSizeMake(320, 930)];
}
Here is my objects view
View
Scroll View
Image View
View
View
Toolbar
It works also with that.
To my understanding "autolayout" set constraint after loading the view so the problem could be that you set your constrains on viewDidLoad and just after that "autolayout" changes that. Try to set this constrains on viewDidAppear.
Get it from: scrollview xcode4.5 autolayout. Thanks.
Always keep in mind that the content view needs to be larger than the UIScrollView instance frame size. If it isn't, it will not enable scrolling.
This applies to UITableView as well. The scrolling for UITableView will not appear unless there are more rows to be displayed than actually are.
I resolved the issue. I just bump the height in [svScroller setContentSize:CGSizeMake(320, 1500)]; and It's working fine.

Populate text in one textfield from text in another

Working on an experiment on the iPad. Tried some variations on how to do this, but I can't seem to get it to work correctly...
I tap a UIButton on my MainViewController and a TextEntryModule is added to the view. TextEntryModule is its own class (for multiple instantiation) and it contains a UITextView called TextEntry (this all works at the moment).
I tap on the TextEntry UITextView and it brings up the keyboard and another view (located in MainViewController) with a UITextView called TextPreview. (this also works at the moment).
The part I'm having trouble with is synching the two UITextViews. The idea being that when I type into TextEntry, the text in TextPreview will also be updated.
Outlets are linked properly for the text fields, but I think I'm missing something "obvious":
TextEntryModule *tm = (AnnotationModule *)currentModule;
TextPreview.text = tm.TextEntry.text
Thanks in advance!
UITextView: delegate.
- (void)textViewDidChange:(UITextView *)textView
Then assign it the value of the other textview in this method.
Edit
#interface MainViewController <UITextViewDelegate> {
...
}
...
#end
Then you implement this method in the implementation file of MainViewController
#implementation MainViewController
//More code
- (void)textViewDidChange:(UITextView *)textView {
TextEntryModule *tm = (AnnotationModule *)currentModule;
TextPreview.text = tm.TextEntry.text
}
#end
Then you will have to set the TextEntryModule object's delegate to self since the controller now conform to the protocol and can "act" upon this notification.
You need to become a UITextFieldDelegate and monitor when text changes in the one field and then update the other field. Take a look at the documentation on it.

Keyboard not show onload

I want the keyboad show automatically onload, but it did not work as i expect
here is the code i use:
- (void)viewDidLoad {
[super viewDidLoad];
[seachBar2 setDelegate:self];
}
- (BOOL)Searchbar2ShouldReturn:(UISearchBar *)searchBar2 {
[searchBar2 becomeFirstResponder];
return YES;
}
Coud somebody will point me how to fix this
thank you somuch
- (void)viewDidLoad {
[super viewDidLoad];
[seachBar2 setDelegate:self];
[seachBar2 becomeFirstResponder];
}
Just came across this, and it helped but the answers are vague.
All you need to do now in iOS 5 is make an outlet connection to your object (for example a UITextField) and then in viewDidLoad method type;
[myTextField becomeFirstResponder];
or for your search bar
[searchBar2 becomeFirstResponder];
Make sure searchBar2 in your code points (IBOutlet) to the searchBar in the Interaface Builder.
in your code:
IBOutlet UISearchBar *searchBar2;
In IB:
goto the search bar's Connections Inspector (apple-2) and drag the Referencing Outlet to File Owner and select searchBar2
Hope this helps.
You do need to override viewDidAppear:, and verify it's actually being called (put a breakpoint or an NSLog() statement in there). You should also determine the language you're coding in (it's Objective C).
Your -Searchbar2ShouldReturn: method will never be called by the system. I think you may need to go back and work through a few of Apple's tutorials here; your grasp of the frameworks seems tenuous, at best.