我在 Xcode
中收到此错误:@interface
for AppDelegate
声明了选择器 performSegueWithIdentifier:sender:
。
我的 main.storyboard
有一个从常规 View 到第一次启动 View 的序列。
我的 AppDelegate.m
是这样说的:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
{
// app already launched
NSLog(@"this app has already been launched partner");
}
else
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];
// This is the first launch ever
NSLog(@"first time launch bb");
[self performSegueWithIdentifier:@"toWelcomeScreen" sender:self];
}
// Override point for customization after application launch.
return YES;
}
如何在第一次启动时使用 segue toWelcomeScreen
显示 View ?
最佳答案
-performSegueWithIdentifier:sender:
不是 <UIApplicationDelegate>
中定义的方法协议(protocol),因此不能在 self
上调用它在这种情况下。 UIViewController
的子类可以回复留言-performSegueWithIdentifier:sender:
, 所以在 AppDelegate
上调用它的 window
的 rootViewController
属性(property)。
[self.window.rootViewController performSegueWithIdentifier:@"toWelcomeScreen" sender:self];
确保您已分配 rootViewController
在这个电话之前。
编辑: rootViewController
是 AppDelegate
的属性的窗口。
编辑 2: 分配 rootViewController
属性,只需将其设置为您的自定义 View Controller 的一个实例即可。
self.window.rootViewController = [[MyCustomViewControllerThatIWantToSegueTo alloc] init];
关于ios - 我在 Xcode : @interface for 'AppDelegate' declares the selector 'performSegueWithIdentifier:sender:' 中收到此错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23875809/