如何在iOS中自动加载第一次单击按钮?
我使用.xib文件创建了一个按钮。我希望应用程序自动加载第一个问题(意思是当应用程序首次启动时ViewController自动加载“showQuestion”方法。我是一个初学者。你是如何做到的?请帮助!谢谢 ViewController.m如何在iOS中自动加载第一次单击按钮?,ios,objective-c,Ios,Objective C,我使用.xib文件创建了一个按钮。我希望应用程序自动加载第一个问题(意思是当应用程序首次启动时ViewController自动加载“showQuestion”方法。我是一个初学者。你是如何做到的?请帮助!谢谢 ViewController.m - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ //call the init method implemented
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
//call the init method implemented by the superclass
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
self.questions = @[@"What is your name?",
@"How old are you?",
@"Where are you from?"];
return self;
}
- (IBAction)showQuestion:(id)sender{
self.questionLabel.text = self.questions[currentIndex];
}
AppDelegate.m文件
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ViewController *vc = [[ViewController alloc] init];
self.window.rootViewController = vc;
return YES;
}
在视图控制器的
-viewDidLoad
方法中,只需手动调用-showQuestion
方法
i、 e.在ViewController.m中,添加以下内容:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self showQuestion:nil];
}
在视图控制器的
-viewDidLoad
方法中,只需手动调用-showQuestion
方法
i、 e.在ViewController.m中,添加以下内容:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self showQuestion:nil];
}
在视图控制器的
-viewDidLoad
方法中,只需手动调用-showQuestion
方法
i、 e.在ViewController.m中,添加以下内容:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self showQuestion:nil];
}
在视图控制器的
-viewDidLoad
方法中,只需手动调用-showQuestion
方法
i、 e.在ViewController.m中,添加以下内容:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self showQuestion:nil];
}
试着这样做:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ViewController *vc = [[ViewController alloc] init];
self.window.rootViewController = vc;
// Autoload first question
[vc showQuestion:nil];
return YES;
}
ViewController.h
- (IBAction)showQuestion:(id)sender;
试着这样做:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ViewController *vc = [[ViewController alloc] init];
self.window.rootViewController = vc;
// Autoload first question
[vc showQuestion:nil];
return YES;
}
ViewController.h
- (IBAction)showQuestion:(id)sender;
试着这样做:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ViewController *vc = [[ViewController alloc] init];
self.window.rootViewController = vc;
// Autoload first question
[vc showQuestion:nil];
return YES;
}
ViewController.h
- (IBAction)showQuestion:(id)sender;
试着这样做:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ViewController *vc = [[ViewController alloc] init];
self.window.rootViewController = vc;
// Autoload first question
[vc showQuestion:nil];
return YES;
}
ViewController.h
- (IBAction)showQuestion:(id)sender;