Stupid and simple question, but I have to ask.
I dragged on Storyboard a button.
How to get access to it?
With drag "Ctrl" not offer.
How do I do it programmatically change setVisible(Yes/No)?
You need an IBOutlet to your UIButton
in your view controller h file
IBOutlet UIButton *mybutton;
#property (nonatomic, retain) UIButton *mybutton;
in your m file
#synthesize mybutton;
and then you should be able to do:
[mybutton setAlpha:0];
Related
I'm trying to put two NSPopover on two Help Buttons on a .xib file.
To do so, I declared in my .h
#interface ExportPreferences : NSPreferencePane <NSPopoverDelegate>
{
NSWindow *window;
NSPopover *popover;
NSUserDefaults *prefs;
NSMutableArray *myArran;
IBOutlet NSButton *images;
IBOutlet NSPopUpButton *modalities;
IBOutlet NSPathControl *path;
IBOutlet NSPopUpButton *tree;
IBOutlet NSPopUpButton *extension;
}
#property (assign) IBOutlet NSWindow *window;
#property (assign) IBOutlet NSPopover *popover;
#end
And two different methods in my .m :
- (IBAction) showInfoTreePopover {
[[self popover] showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMaxXEdge];
}
- (IBAction) showInfoTypePopover {
[[self popover] showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMaxXEdge];
}
Then, in my .xib I declared
A Popover with its Popover View Controller
A Custom View
A Label (on the CV)
And I linked :
The Help Button to its corresponding method (one for the Tree, one for the Type)
The File's Owner to the Popover
The Popover View Controller to the Custom View
Since I do have two NSPopover to implement, I did all of this twice, two Popover, two Popover View Controller, two Custom View, two labels.
When I compile, everything goes right, but when I test it, it appears that only my second Popover shows up on the two buttons. It seems that implementing the second Popover, erased the first one.
how may I patch that ?
Alright, I answered my own question but I think I might give the answer if anyone faces the same problem.
When using two NSPopovers, I had to declare two different Outlets,
NSPopover *treePopover;
NSPopover *typePopover;
Also, two properties
#property (assign) IBOutlet NSPopover *treePopover;
#property (assign) IBOutlet NSPopover *typePopover;
And now, the linking works perfectly.
I have 2 UIViews. One is the main menu the second one is the actual game. When it's game over, a Retry button appear, i want the button to reset the UIView so the game can start over. Right now i have the "Retry" button connected to the main menu but i don't like the fact that you gotta go by the main menu to retry.
I tried adding this line of code"
[GameViewController.view setNeedsDisplay]
In my "GameOver" method but i had an error pointed to the .view and it said "property view not found on object of type GameViewController".
EDIT
GameViewController.h
int BirdFlight;
int RandomTopTunnelPostition;
int RandomBottomTunnelPosition;
int ScoreNumber;
NSInteger HighScoreNumber;
#interface GameViewController : UIViewController
{
IBOutlet UIImageView *Bird;
IBOutlet UIButton *StartGame;
IBOutlet UIImageView *TunnelTop;
IBOutlet UIImageView *TunnelBottom;
IBOutlet UIImageView *Top;
IBOutlet UIImageView *Bottom;
IBOutlet UIButton *Exit;
IBOutlet UILabel *ScoreLabel;
NSTimer *BirdMovement;
NSTimer *TunnelMovement;
SystemSoundID PlaySoundID;
SystemSoundID PlaySoundID2;
SystemSoundID PlaySoundID3;
}
-(IBAction)StartGame:(id)sender;
-(void)BirdMoving;
-(void)TunnelMoving;
-(void)PlaceTunnels;
-(void)Score;
-(void)GameOver;
#end
I went through guide from Apple "Your first iOS app"
and now I have a button, which is not declared in ViewController:
#interface HelloWorldViewController : UIViewController <UITextFieldDelegate>
- (IBAction)changeGreeting:(id)sender;
#property (weak, nonatomic) IBOutlet UITextField *textField;
#property (weak, nonatomic) IBOutlet UILabel *label;
#property (copy, nonatomic) NSString *userName;
#end
Now i can remove label (and textField), using [label removeFromSuperview]; but i dont understand how to do it with button. Can someone help?
You should add an IBOutlet to the button as you did for the textfield and the label:
#property (weak, nonatomic) IBOutlet UITextField *textField;
#property (weak, nonatomic) IBOutlet UILabel *label;
#property (weak, nonatomic) IBOutlet UIButton *button; // Don't forget to link to this from Interface Builder
// ...
Then you can remove the button using:
[button removeFromSuperview];
Also note that the tutorial you linked to says:
The sender parameter in the action method refers to the object that is sending the action message (in this tutorial, the sender is the button).
So if you want to remove the button when it is tapped (inside changeGreeting:), then you don't need the IBOutlet because you already have a reference to the button in the sender parameter:
- (IBAction)changeGreeting:(id)sender
{
UIButton *button = (UIButton *)sender;
// ...
[button removeFromSuperview];
// ...
}
You need to declare the button in the controller like you did as an IBAction and this time declare this as an Outlet(IBoutlet).. this way you will get its reference in code..
Alternatively .. you can set a tag to the button in Interface Builder
..
and then retrieve in code using viewWithTag: method
I am attempting to hide a NSButton that performs miniaturize when a different NSButton on the interface is clicked. My attempts thus far have been unsuccessful, this is what I have tried:
.h file:
#interface AppDelegate : NSObject <NSApplicationDelegate> {
IBOutlet NSWindow *window;
IBOutlet WebView *webView;
IBOutlet NSButton *doMinimize;
}
#property (assign) IBOutlet NSWindow *window;
#property (assign) IBOutlet NSButton *button;
#property (nonatomic, retain) IBOutlet WebView *webView;
.m file:
#implementation AppDelegate
#synthesize window;
#synthesize webView;
#synthesize doMinimize;
- (IBAction)toggleFullscreen:(id)sender
{
...
[doMinimize setEnabled:NO];
[doMinimize setTransparent:YES];
...
}
It appears that no matter in what action I try to disable and make the button transparent, it doesn't seem to respond to anything. Do I have to give the button it's own class to make this work? If so, how would I then be able to modify that button from an IBAction inside of a different class?
I apologize in advance if my question is silly, I'm relatively new to the world of Objective-C and am just now starting to get my feet wet.
Thanks in advance.
Have you tried -setHidden:?
[doMinimize setHidden:YES];
I'm sure there's an easy way to do this:
for (i=0; i<10; i++) {
IBOutlet UIButton *button+i;
}
instead of this:
IBOutlet UIButton *button0;
IBOutlet UIButton *button1;
IBOutlet UIButton *button2;
IBOutlet UIButton *button3;
IBOutlet UIButton *button4;
IBOutlet UIButton *button5;
IBOutlet UIButton *button6;
IBOutlet UIButton *button7;
IBOutlet UIButton *button8;
IBOutlet UIButton *button9;
but my objective-c is not so good. Can someone help?
This is not possible. IBOutlet is a keyword that is interpreted by Interface Builder.
It only makes sense in the .h file, never in any loop.