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
Related
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!
i have two screen. i want click button first screen after navigation bar change in second screen.
i using storyboards
first screen code
-(IBAction) ChangeSecondPageTitle: (id) sender {
SecondViewController *second=[[self storyboard] instantiateViewControllerWithIdentifier:#"second"];
second.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
second.detailTitle.topItem.title=#"example";
[self presentModalViewController:second animated:YES];
}
second screen.h
#property (weak, nonatomic) IBOutlet UINavigationBar *detailTitle;
I guessing you are trying to set title for your second screen navigation bar.
Use a navigation controller to present your second screen.
In SecondDetailViewController instance, maintain a NSString property.
#property (strong, nonatomic) NSString *navBarTitle;
In viewDidLoad, just set the title.
[self setTitle:navBarTitle];
Actually the reason your code is not working is you set the property to your nav bar and then your viewDidLoad get called. In viewDidLoad it loads the nib file and return new allocated navBar. So to Solve this take a global string set it from first view and then in second in viewDidLoad set your navbar's title. Follow
Adithya's answer for that.
In second screen declare a property
#property (strong, nonatomic) NSString *newTitle;
and in viewDidLoad
self.title = _newTitle;
and in your first screen
...
second.newTitle = #"NEW_TITLE";
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
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...
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.