Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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 在swift中实现GTScrollNavigationBar_Ios_Objective C_Iphone_Swift_Swift2 - Fatal编程技术网

Ios 在swift中实现GTScrollNavigationBar

Ios 在swift中实现GTScrollNavigationBar,ios,objective-c,iphone,swift,swift2,Ios,Objective C,Iphone,Swift,Swift2,我正在尝试在我的swift项目中使用。我不熟悉斯威夫特和iOS。因此,我使用obj-C中的演示项目来实现它。 演示项目的AppDelegate如下所示 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen ma

我正在尝试在我的swift项目中使用。我不熟悉斯威夫特和iOS。因此,我使用obj-C中的演示项目来实现它。 演示项目的AppDelegate如下所示

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    self.viewController = [[DemoTableViewController alloc] initWithStyle:UITableViewStylePlain];
    self.navController = [[UINavigationController alloc] initWithNavigationBarClass:[GTScrollNavigationBar class] toolbarClass:nil];
    [self.navController setViewControllers:@[self.viewController] animated:NO];
    self.window.rootViewController = self.navController;
    [self.window makeKeyAndVisible];
    return YES;
}
我已经在swift中实现了它,如下所示

var window: UIWindow?
    var navigationController : UINavigationController?
    var viewController : UIViewController?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        self.window?.backgroundColor = UIColor.whiteColor()

        self.viewController = TableViewController(style: UITableViewStyle.Plain)
        self.navigationController = UINavigationController(navigationBarClass: GTScrollNavigationBar.self, toolbarClass: nil)
        (self.window!.rootViewController as! UINavigationController).viewControllers = [viewController!]
        self.window?.rootViewController = self.navigationController
        self.window?.makeKeyAndVisible()


        return true
    }
它显示了在此行展开可选值时意外发现的错误,该值为零
(self.window!.rootViewController as!UINavigationController)。viewControllers=[viewController!]

有人能告诉我我做错了什么吗?

您的代码应该翻译成Swift,如下所示:

self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.backgroundColor = UIColor.whiteColor()

self.viewController = UITableViewController(style: UITableViewStyle.Plain)

self.navigationController = UINavigationController(navigationBarClass: GTScrollNavigationBar.self, toolbarClass: nil)
self.navigationController?.viewControllers = [viewController!]

self.window?.rootViewController = self.navigationController
self.window?.makeKeyAndVisible()
我使用
navigationBar
而不是
GTScrollNavigationBar
来测试它;它似乎在工作