gpt4 book ai didi

ios - 无法在Swift中设置IndexPath行

转载 作者:行者123 更新时间:2023-12-01 21:42:28 25 4
gpt4 key购买 nike

以下代码会产生运行时错误,我不知道怎么办。有什么想法吗?

    var foo: IndexPath
foo = IndexPath()
foo.row = 1

var i = 0

enter image description here

最佳答案

迅速有一个先决条件才能访问indexpath

/// The section of this index path, when used with `UITableView`.
///
/// - precondition: The index path must have exactly two elements.
public var section: Int

/// The row of this index path, when used with `UITableView`.
///
/// - precondition: The index path must have exactly two elements.
public var row: Int

enter image description here

如果要访问或更改行,则需要使用行和节初始化indexPath
 var foo: IndexPath
foo = IndexPath(row: 0, section: 0)
foo.row = 1 // return foo (1,0)

关于ios - 无法在Swift中设置IndexPath行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62452415/

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