gpt4 book ai didi

ios - swift 中的 viewControllers indexOfObject

转载 作者:搜寻专家 更新时间:2023-11-01 06:07:58 24 4
gpt4 key购买 nike

我有这个 objective-c 方法,我正在尝试将其重写为 swift。

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
int index = [navigationController.viewControllers indexOfObject:viewController];
self.pageControl.currentPage = index;
}

我在快速编写这一行时遇到困难:

int index = [navigationController.viewControllers indexOfObject:viewController];

我如何访问 IndexOfObject?

最佳答案

在 Swift 1.2 (Xcode 6.x) 中

let index = find(navigationController.viewControllers, viewController)!

在 Swift 2.0 (Xcode 7.x) 中

let arrayOfVCs = navigationController.viewControllers as Array
let index = arrayOfVCs.indexOf(viewController)

关于ios - swift 中的 viewControllers indexOfObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32581962/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com