Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS中自动加载第一次单击按钮?_Ios_Objective C - Fatal编程技术网

如何在iOS中自动加载第一次单击按钮?

如何在iOS中自动加载第一次单击按钮?,ios,objective-c,Ios,Objective C,我使用.xib文件创建了一个按钮。我希望应用程序自动加载第一个问题(意思是当应用程序首次启动时ViewController自动加载“showQuestion”方法。我是一个初学者。你是如何做到的?请帮助!谢谢 ViewController.m - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ //call the init method implemented

我使用.xib文件创建了一个按钮。我希望应用程序自动加载第一个问题(意思是当应用程序首次启动时ViewController自动加载“showQuestion”方法。我是一个初学者。你是如何做到的?请帮助!谢谢

ViewController.m

- (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;