IBAction is not shown in IB? - iphone

i have done like
#interface tabViewController : UIViewController
{
IBOutlet UIButton* button_first;
IBOutlet UIButton* button_second;
IBOutlet UIButton* button_third;
IBOutlet UIButton* home;
}
but i could not in file owner those button? what i have to do? any help please? i have set everything correctly (viewcontroller, view)...the day before it was working...i tried in interface builder to reload classes etc...why it happens?

You should have this:
VC Header file:
#interface tabViewController : UIViewController
{
IBOutlet UIButton* button_first;
IBOutlet UIButton* button_second;
IBOutlet UIButton* button_third;
IBOutlet UIButton* home;
}
- (IBAction) ButtonMethod;
VC .m file:
- (IBAction) ButtonMethod
{
// Code goes here
}
You should now be able to link to the "ButtonMethod" in Interface Builder. Right click the button, click on the circle next to "Touch Up Inside" and link it to "ButtonMethod".
Hope that helps.
EDIT:
This images doesn't show the blue line that appears when selecting but shows what you have to press:

Did you declare them as properties?
Using:
in .h-fle
#property(nonatomic, retain) UIButton *button_first;
And in .m-file:
#synthesize button_first?
?

have a look at the nib file. may be you have changed the class of that nib file.
Check out whether you see tabViewController in fornt of File's owner.
I am sure you have changed the class so the change is not getting reflected of IBOUTLET in files owner.
and as told by #GUBB its not at all required to set hte property and synthesis of the stuffs..
hAPPY cODING...

Related

No visible #interface for UIButton declares the selector"setbookmarkState

Declared BOOL
#property (nonatomic, assign) BOOL BookmarkState;
When using the BOOL for UIButton added on navigationbar using storyboard
[_bookmarkbtn setBookmarkState:NO];
then gets ARC Semantic issue
No visible #interface for UIButton declares the selector"setbookmarkState
EDIT:
PageViewController h file
#interface PageViewController : UIViewController <UIPageViewControllerDelegate, UIPageViewControllerDataSource>
#property (nonatomic, assign) BOOL BookmarkState;
#end
PageViewController m file
#interface PageViewController () {
BOOL BookmarkState;
}
#property (strong, nonatomic) IBOutlet UIButton *bookmarkbtn;
#implementation PageViewController
UIButton has no property called bookmarkState.
If you want to disable your button bookmarkbtn, use [_bookmarkbtn setEnabled:NO];
Or if you want to deselect it, use [_bookmarkbtn setSelected:NO];
Or if you want to unhighlight it, use [_bookmarkbtn setHighlighted:NO];
If you want to set the bookmarkState to NO, use [self setBookmarkState:NO];
Edit: it seems like you've named the booleans differently (one with lowercase, and one with uppercase) so my question is - are you certain of what are you doing / of what are you trying to accomplish?
Pardon me if it will sound rude or disrespectful, but calling setbookmarkState on UIButton is clearly showing that you aren't quite sure of how to do something you that you need.
Also, XCode should give you an error stating that no visible interface for UIButton declares the selector setbookmbarState:
First of all - as stated, UIButton has no property bookmarkState.
Then, calling an autosynthesized setter method always implies that you use setMyProperty, not setmyProperty, or setmyproperty. It's weird how you got it to run :)
Good luck!

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

Trying to disable button using button.enabled = false, but having no luck

I'm getting frustrated because I am failing to have any control over my bar button items or my UIToolbar. I am trying to disable a UIBarButtonItem, but it continues to respond to touch events. Here is what I have done, the code is so simple I don't know why it isn't working.
in my .h:
IBOutlet UIBarButtonItem *button;
#property (nonatomic,retain) IBOutlet UIBarButtonItem *button;
and in .m:
#synthesize button;
-(void)function{
button.enabled = false;
}
Am I doing something wrong with the viewcontroller delegate? I don't understand why I get no response. Thanks for your help.
This is correct:
button.enabled = false;
So are you sure that this method is actually being called? (And if this is your actual code, you have a method called 'function'?)
You might be able to achieve this with:
button.target = nil;
button.action = nil;
More:
http://developer.apple.com/library/ios/ipad/#documentation/uikit/reference/UIBarButtonItem_Class/Reference/Reference.html
did you connect the button in the xib file to the outlet in the .h file? You may have set the target/IBAction, but you need to setup the reciprocal path. i.e. dragging from the File Owner, which is most likely the viewController, to the button. Then selecting the name of the IBOutlet in your .h file.
Good luck

UIBarButtonItem not showing up

I have the following code:
#interface PartyListViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
UIBarButtonItem * toggle;
//ProfileViewController *profileViewController;
}
#property(nonatomic, retain) IBOutlet UIBarButtonItem *toggle;
- (IBAction)toggleAction:(id)sender; // when the toggle button is clicked
#end
My interface builder looks like this:
I have added:
self.navigationItem.rightBarButtonItem = self.toggle;
in my viewDidLoad, why doesn't the button show up?
If I create my button via code, it is there...
Check if your toggle button is not nil when assigned it to the rightBarButtonItem property!
I always create my barButtonItem via code....
I am very curious why you add IBOutlet at both place. Generally, I will add this keyword at where I declare the property.
I declared it as a tableviewcontroller and it should be a viewcontroller
do you have
#synthesize toggle;
getting called in your implementation? If you don't synthesize the object, it won't make getters and setters for you, so that may be why setting the rightBarButtonItem isn't working, as there is no getter for the toggle barButtonItem, so you're setting it to nil

How to trigger methods with UIButtonBarItem?

I have a a xib with a toolbar and on that I have 2 buttons all made in IB.
I can connect my outlets to the buttons but when I click them the method isn't triggered?
Why is that?
In my header file I have this:
#property (nonatomic, retain) IBOutlet UIBarButtonItem *cancelEntry;
#property (nonatomic, retain) IBOutlet UIBarButtonItem *saveEntry;
-(IBAction) cancelEntry:(id) sender;
-(IBAction) saveEntry:(id) sender;
In my .m file I got this:
-(IBAction) cancelEntry:(id) sender {
NSLog(#"cancel");
}
-(IBAction) saveEntry:(id) sender {
NSLog(#"save");
}
All compiles as it should but no nothing in the log when clicking the buttons.
What should I do to get it to work?
Sounds like you connected your outlets to the buttons, but didn't connect the buttons to the actions.
Right click Cancel the UIBarButtonItem in Interface Builder.
Hover over Selector, then drag the + that appears onto File's Owner.
Connect it to cancelEntry:.
Repeat for Save.
Instead of using (id) for your IBActions, you should probably use (UIBarButtonItem *). That'll prevent you from connecting a different object type to those IBActions.