hide and show intermittent uilabel and uinavigation title? - iphone

Hello to all people!!
I need to made one uilabel thats shows and hide intermittently likes information message in the main view...
I need the same in the title of the navigation bar... Is this possible?
any suggestions please...

Sure.
Supposing you have:
#property (nonatomic, retain) IBOutlet UILabel * myLabel;
You can easily:
[self.myLabel setHidden:YES];
or
self.myLabel.hidden = YES;
or
[self.myLabel setHidden:NO];
or
self.myLabel.hidden = NO;
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html

Related

Change background button2 into button1 iPhone

I am a beginner in Xcode, and I have a problem.
I have 2 buttons:
- (IBAction) HIGH1: (id) sender
- (IBAction) HIGH2: (id) sender
When the user clicks the HIGH1button, I want to change the background (with image) of the button HIGH2.
How can I achieve this?
You need to create IBOutlet for the buttons to change them.
Control+drag the buttons from Interface Builder to the .h file to create the outlets. Something like this:
#property (weak, nonatomic) IBOutlet UIButton *HIGH1;
#property (weak, nonatomic) IBOutlet UIButton *HIGH2;
//Dont forget to #synthesize
On the IBAction method you then call:
- (IBAction) HIGH1: (id) sender
{
self.HIGH2 setBackgroundImage:[UIImage imageNamed:#"myButtonImage"] forState:UIControlStateNormal];
}
Make sure you have an image with the name you choose in your application bundle, and that the IBOutlet to the buttons is properly connected (The gray circle on the left size of the IBOutlet must have a small black circle inside it)
[HIGH1 addTarget:self
action:#selector(buttonDidPushed)
forControlEvents:UIControlEventTouchUpInside];
then,
-(void)buttonDidPushed
{
HIGH2.backgroundColor = [UIColor blackColor];
[self.view addSubview:HIGH2];
}
I hope this code help you.
access your ivar from HIGH2 and set setBackgroundImage:forState: on HIGH1

how to make a drop down list for iphone application

I want to make a drop down list for iphone application i want that when user click it show list and when click on any button it shows that value and hides list i have implemented using the follwoing code but this work only for one value not for others
#interface DropDownViewController : UIViewController {
IBOutlet UILabel*ddText;
IBOutlet UILabel*ddMenu;
IBOutlet UIButton*ddMenuShowButton;
}
#property (nonatomic, retain) IBOutlet UILabel *ddText;
#property (nonatomic, retain) IBOutlet UIView *ddMenu;
#property (nonatomic,retain) IBOutlet UIButton *ddMenuShowButton;
- (IBAction)ddMenuShow:(UIButton *)sender;
- (IBAction)ddMenuSelectionMade:(UIButton *)sender;
#end
#implementation DropDownViewController
#synthesize ddMenu, ddText;
#synthesize ddMenuShowButton;
- (IBAction)ddMenuShow:(UIButton *)sender
{
self.ddMenu.hidden = NO;
[sender setTitle:#"▲" forState:UIControlStateNormal];
}
- (IBAction)ddMenuSelectionMade:(UIButton *)sender
{
self.ddText.text = sender.titleLabel.text;
[self.ddMenuShowButton setTitle:#"▼" forState:UIControlStateNormal];
self.ddMenu.hidden = YES;
}
I have three button red grenn blue first is red it works only for red only not for others how to solve this i have used this following this tutorial
http://www.edumobile.org/iphone/iphone-programming-tutorials/a-simple-drop-down-list-for-iphone/
Add UIbutton near your textfield.While clicking that button create UITableview according to your textfileld size.(Hope you know about creating Uitableview)and then load your listview contents in "cellForRowIndex".While selecting the row of the table,you can get the value from "didselectrowatIndexPath" and load it in textfield.After that remove UItableview.
It would be good if you use iPhone tools in your application. You should use UIPickerView in the place of drop down list. It looks good and provides better interface in mobile application

iphone. making UITextView but won't make it visible

#interface SomeViewController : UIViewController <UITextViewDelegate>
#property (retain, nonatomic) IBOutlet UIImageView *imageView;
#property (nonatomic, retain) UIImage *image;
#property (nonatomic, retain) IBOutlet UITextView *textView;
I need textview(editable) in my view controller.
so I set protocol ,
and also, IB to the file's owner, too. (I don't know, is it unnecessary?)
And my .m file.... viewDidLoad..
_textView = [[UITextView alloc]init];
[_textView setFrame:CGRectMake(8, 110, 304, 82)];
[_textView setFont:[UIFont boldSystemFontOfSize:12]];
_textView.editable = YES;
//[textView setText:#"hdgffgsfgsfgds"];// if uncommented, this actually visible...
[self.view insertSubview:_textView atIndex:2];
So far, it's working. But I want these methods to run...
- (void)textViewDidChange:(UITextView *)textView
{
if([_textView.text length] == 0)
{
_textView.text = #"Foobar placeholder";
_textView.textColor = [UIColor lightGrayColor];
_textView.tag = 0;
}
}
But after build, my textview is still empty.
What did I wrong?
You need to add the delegate to your textview, try with this:
_textView.delegate = self;
On the other hand,
textViewDidChange
Will only work when you change your text, if you want to place a text in the textview, you can do:
_textView.text = #"Foobar placeholder";
_textView.textColor = [UIColor lightGrayColor];
_textView.tag = 0;
In your ViewdidLoad
When synthesizing the textView, do you do it like #synthesize textView = _textView so that you can use the underscored name? Usually the underscored one is used only in the setter/getter methods (for instance when overriding them).
Note that
The text view calls this method in response to user-initiated changes to the text. This method is not called in response to programmatically initiated changes.
This is from Apple's documentation for the method you are using. This means if you are changing the text through the code, the method will not get fired.
Are you expecting [textView setText:#"hdgffgsfgsfgds"] to in turn invoke textViewDidChange:? Calling setText will not automatically invoke the textViewDidChange:.

label and textview not responding to setText:

I have two properties setup properly in Objective-C:
#property (nonatomic, retain) IBOutlet UILabel *label;
#property (nonatomic, retain) IBOutlet UITextView *textView;
I have synthesised them and linked them in the NIB file however when I come to use them like:
if (row==0) {
NSLog(#"First text");
[self.label setText:#"LABEL 1"];
[self.textView setText:#"LABEL 1"];
}
else if (row==1) {
NSLog(#"Second text");
[self.label setText:#"LABEL 2"];
[self.textView setText:#"LABEL 2"];
}
The text is not changing however the NSLog is being called and not the setText: and I was wondering why...
It should be a IBOutlet for you to link them in xib.
Now that you updated your question, the problem may be you have not connected it to your viewcontroller's property. Hence the result. Add more details to your question.
Make sure that Xib and IBOutlet were correct linked.
Make sure that your label and testView are visible. You can set their background color red or other any color different with bg to check their visibility.
Make sure that the line "[self.label setText:#"LABEL 1"];" had ran. you can check the NSLog.
Make sure that the line "[self.label setText:#"LABEL 1"];" was running in main thread.
If your properties are outlets you should declare them as follows:
#property (nonatomic, retain) IBOutlet UILabel *label;
#property (nonatomic, retain) IBOutlet UITextView *textView;
The behaviour you are seeing suggests that you haven't set up the outlet correctly.
FIRST METHOD:
It should be declared as an IBOutlet and you should link it to a label and textView in XIB as Praveen S has said.
SECOND METHOD:
Other option if it is not a label in XIB then you need to allocate and initialize the label to set its text i.e. to access its properties/methods/attributes.
UILabel *label = [[UILabel alloc] init];
[label setText:#"Text"];
label.frame = CGRectMake(0,0,20,20);
Hope this helps.

adding view controller in navigationcontroller issue

I have the following class:
#interface DiscountDetailViewController : UIViewController {
UILabel * titleLabel;
UILabel * offerLabel;
}
#property (nonatomic, retain) IBOutlet UILabel * titleLabel;
#property (nonatomic, retain) IBOutlet UILabel * offerLabel;
#end
and I tried to do the following in the previous view:
discount = [[DiscountDetailViewController alloc] initWithNibName:#"DiscountDetailViewController" bundle:nil];
discount.titleLabel.text = temp.vendor;
discount.offerLabel.text = temp.description;
[self.navigationController pushViewController:discount animated:YES];
The issue is that, discount.titleLabel.text when printed is always null... I think it's because I define the titleLabel using interface builder.. so is there a way to resolve this?
I've hooked it up with IB as well..
i don't believe the iboutlets get hooked up until the view is on screen for the first time.
you could try setting the label after its displayed, or add another property to store the label text, then set the iboutlet label based on this new property in viewDidLoad in your DiscountDetailViewController.
If your outlets are properly connected then it is only because your titleLabel will not be available until your viewIsLoaded around -(void)viewDidLoad, I recommend you use an NSString property that can set the title label once view is loaded and update it when it is changed (override setter), or if you know your view is about to show try calling view first.
discount = [[DiscountDetailViewController alloc] initWithNibName:#"DiscountDetailViewController" bundle:nil];
//Force view to load, do not really recommend (though for some reason I am showing you how)
[discount view];
discount.titleLabel.text = temp.vendor;
discount.offerLabel.text = temp.description;
[self.navigationController pushViewController:discount animated:YES];