SwiftUI PageViewController 索引

问题描述 投票:0回答:1

我在最新版本的 Xcode(SwiftUI)上使用 pageViewController。当我尝试为数据源建立索引时,它说我无法这样做,因为:“无法分配给值:'index'是一种方法”和“无法将类型'Int'的值分配给类型'(Any) -> Int'”

代码:

guard让startingViewController=detailViewControllerAt(index:currentViewControllerIndex)else{ 返回 } pageViewController.setViewControllers([startingViewController], 方向: .forward, 动画: true) }

func detailViewControllerAt(index: Int) -> DataViewController? {
    if index >= dataSource.count || dataSource.count == 0 {
        return nil
    }
    
    guard let dataViewController = storyboard?.instantiateViewController(withIdentifier: String(describing: DataViewController.self)) as? DataViewController else {
        return nil
}
    dataViewController.index = index
    dataViewController.displayText = dataSource[index]
    
    return dataViewController
}

}

我使用这个视频作为教程,项目中没有编写其他代码,我在 17:44 中: https://www.google.com/search?sca_esv=597709555&sxsrf=ACQVn09NEQlIpK_V87flvqDZlCqLzjn4Gw:1705033257435&q=how+to+set+up+a+page+view+controller+for+albums&tbm=vid&source=lnms&sa=X&ved=2 ahUKEwjG147t_9aDAxXQkokEHZqFBXAQ0pQJegQICRAB&biw=1920&bih =968&dpr=1#fpsstate=ive&vld=cid:14bda130,vid:hIMRn_LdvOg,st:0

任何帮助将不胜感激

我是一个新编码员,我找到了几个解决方案但无济于事,请帮忙

xcode swiftui indexing storyboard datasource
1个回答
0
投票

尝试使用

dataViewController.index(ofAccessibilityElement: index)
而不是
dataViewController.index = index

© www.soinside.com 2019 - 2024. All rights reserved.