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
Related
I have added NSWindow element in my.xib file and inserted some element to it, such as imageView. And then created class of type NSWindow named customNSWindow and assign these class to the xib element which I have created(NSWindow). Now from another WindowController I need to show/hide the customNSWindow. This is done by putting an outlet to the WindowController.
viewController.h
#property (strong) IBOutlet NSWindow *ImageEditWindow;//(custom window)
viewController.mm
-(IBAction)ButtonClick:(id)sender {
if(! [_ImageEditWindow isVisible] ){
[_ImageEditWindow makeKeyAndOrderFront:sender];
}
}
But I don't know I how to update image in ImageEditWindow, I cannot find way to call a method inside the custom class I created, using _ImageEditWindow outlet.
Edit
Here is the custom class for NSWindow
CustomIKImageEditor.h
#interface CustomIKImageEditor : NSWindow
#property (weak) IBOutlet IKImageView *IKImg;
-(void) updateIKImage: (NSImage*)staticImageToEdit;
#end
CustomIKImageEditor.mm
-(void) updateIKImage: (NSImage*)staticImageToEdit {
NSDictionary* _imageProperties;
CGImageRef source = [self CGImageCreateWithNSImage: staticImageToEdit];
_imageProperties = NULL;
[_IKImg setImage: source imageProperties: NULL];
}
This line:
#property (strong) IBOutlet NSWindow *ImageEditWindow;//(custom window)
Should be:
#property (strong) IBOutlet CustomIKImageEditor *ImageEditWindow;//(custom window)
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.
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];
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 have the following structure in my iPad App:
Application
UINavigationController (Providing the top bar with UIBarButtons etc.)
Initial Login screen
Second login screen
I am not sure how I should now set this up in Interfacebuilder correctly. My guess would be that I create two ViewControllers:
LoginVC1: (This one should also include the NavigationController since it is the first of the two screens)
LoginVC2: Based on some delegate callback from LoginVC1 my application would push to this ViewController.
This is my LoginVC1 in IB:
LoginVC1 http://k.minus.com/jpamEAFkBjpKT.png
And when I present it modally it looks like this which is not what I want:
Result http://k.minus.com/jHAYRnY788jFt.png
The result:
Nor the title of the ViewController nor the Cancel button is shown
The view seems to be empty despite my view in IB
I have set the Presentation mode of the UINavigationController to FormSheet which is ignored too since it is displayed in fullscreen.
What am I doing wrong?
Kjuly I simply do presentModalViewController to show the dialog, but
since my UINavigationControler contains a UIViewController (See
nib-screen), I would assume that this ViewController is displayed when
the modal is shown.
Not always Besi. Adding it to the UINavigationController Hierarchy doesn't add is as the rootViewController. That must be done in code like this:
UIViewController *rootViewController = [[[ExamplesViewController alloc] init] autorelease];
UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
Also, check that you are presenting the NavigationController, and not the ViewController modally.
To solve the NavigationBar title issue, try setting the self.title property in the
-(void)viewDidload method and see if that works. If not, try self.//instance of UINavigationController//.navigationBar.title = #"string".
As for the other buttons not showing up, my guess is that if setting the root controller in code doesn't help, then you only made reference to them in the .h, instead of instantiating them. So either call something like this in the .h:
//.h
#implementation ExampleViewController: UIViewController <UITextFieldDelegate> {
IBOutlet UIBarButtonItem * CancelButton;
IBOutlet UITextField * usernameField;
IBOutlet UITextField * passwordField;
IBOutlet UIButton * loginButton;
}
#property (nonatomic, retain) IBOutlet UIBarButtonItem * CancelButton;
#property (nonatomic, retain) IBOutlet UITextField * usernameField;
#property (nonatomic, retain) IBOutlet UITextField * passwordField;
#property (nonatomic, retain) IBOutlet UIButton * loginButton;
Then connect the outlets in the XIB, or instantiate the buttons in the .m with:
//.m
-(void)viewDidLoad {
//do stuff
CancelButton = [[[UIBarButtonItem alloc]initWithTitle:#"Cancel" style:UIBarButtonItemStyleDone target:self action:#selector(dismissSelf)]autorelease];
//do more stuff
}