使用xcode 4.3中的標籤式視圖應用程序。不進入我的構造函數
我只是試圖初始化我的FirstViewController的.h文件中聲明的一些變量。我試圖通過在我的.m文件中創建一個構造函數像這樣。
.h文件中:
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController {
IBOutlet UITextField *currentGuess;
IBOutlet UILabel *attemptsMade;
IBOutlet UILabel *attemptsLeft;
IBOutlet UITextView *hints;
int numberToGuess;
int numberOfGuessesMade;
int maxGuesses;
int maxGenNumber;
NSMutableArray *allGuesses;
}
- (id) init;
@end
.m文件
#import "FirstViewController.h"
@interface FirstViewController()
@end
@implementation FirstViewController
- (id) init {
NSLog(@"entered constructor!");
if(self = [super init])
{
numberToGuess = 0;
numberOfGuessesMade = 0;
maxGuesses = 3;
maxGenNumber = 10;
}
return self;
}
試過下面的答案,最後使用viewDidLoad代替。 – 2013-01-20 03:45:10