Yes, yours looks like I was expecting mine to look.
Note that viewDidLoad (below) does work correctly, producing the expected results in the simulator!
Hangman3ViewController.h:
@interface Hangman3ViewController : UIViewController {
}
@property ( nonatomic ) NSInteger wordLength;
@property ( retain, nonatomic ) NSString *alphabet;
@property ( nonatomic ) unichar guess;
@property ( nonatomic ) NSInteger guessNo;
@property ( retain, nonatomic ) NSMutableString *board;
@property ( retain, nonatomic ) IBOutlet
UILabel *boardLabel;
@property ( retain, nonatomic ) IBOutlet
UILabel *guessNumberLabel;
@property ( retain, nonatomic ) IBOutlet
NSArray *keyboardButtons;
- (IBAction)letter:(id)sender;
- (void)showBoard;
@end
and, Hangman3ViewController.m:
#import "Hangman3ViewController.h"
@implementation Hangman3ViewController
@synthesize wordLength = _wordLength; // preprocessor command to gen getter/setter and instance variable
@synthesize boardLabel = _boardLabel; // preprocessor command to gen getter/setter and instance variable
@synthesize guessNumberLabel = _guessNumberLabel; // Guess #n
@synthesize keyboardButtons = _keyboardButtons; // array of buttons
@synthesize alphabet = _alphabet; // A-Z unichars
@synthesize guess = _guess; // unichar
@synthesize guessNo = _guessNo; // int
@synthesize board = _board;
- (IBAction)letter:(id)sender
{
/*
Get letter from sender - driven when key button is pressed.
The button's tag is an int from 0-25, identifying what letter of the alphabet it is.
Extract that unichar from ALPHABET as 'guess'. Then, disable the button,
which has been defined to have its text turn white (invisible) when disabled.
*/
UIButton *button = (UIButton *)sender;
self.guess = [self.alphabet characterAtIndex: button.tag];
NSLog(@"Received keystroke: %C", self.guess);
[button setEnabled:NO];
}
- (void)showBoard
{
self.boardLabel.text = self.board;
self.guessNumberLabel.text = [NSStringstringWithFormat:@"Guess #%d", self.guessNo];
}
- (void)dealloc
{
[_boardLabelrelease];
[_guessNumberLabelrelease];
[_keyboardButtonsrelease];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[superdidReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
NSLog(@"Hello from viewDidLoad");
[superviewDidLoad];
self.alphabet = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // unichar string
self.wordLength = 7; // temp - will be set from flipside later on
self.guessNo = 1;
[self.boardsetString:@"_______"]; // actually dynamic based on wordLength
self.board = @"_______";
[selfshowBoard];
}
- (void)viewDidUnload
{
[superviewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end