ios - 我在 Xcode : @interface for 'AppDelegate' declares the selector 'performSegueWithIdentifier:sender:' 中收到此错误

标签 ios objective-c xcode

我在 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 上调用它的 windowrootViewController属性(property)。

[self.window.rootViewController performSegueWithIdentifier:@"toWelcomeScreen" sender:self];

确保您已分配 rootViewController在这个电话之前。 编辑: rootViewControllerAppDelegate 的属性的窗口。

编辑 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/

相关文章:

iphone - UITextField 背景行为从 iOS 4 到 iOS 5 的变化

ios - Spotify iOS SDK 刷新 token

android - iOS能像安卓一样接收广播吗?

ios - 卸载iOS应用程序时是否删除了 Realm 文件

ios - 如何处理 Iphone 5 视网膜显示检查?

objective-c - 使用未声明的类型 "NSManagedObjectModel"

xcode - Xcode中的矩形选择

objective-c - 非常奇怪的 ARC 内存泄漏

ios - 适用于 iOS 的 Pusher 与 PubNub

xcode - 使用 Xcode Memory Graph Debugger 时出现 "Memory Graph Debugger: no serialized memory graph received from LeakAgent"错误