繁体   English   中英

SWIFT-创建/更改长度等于1的NSIndexPath

[英]SWIFT - Create/Change NSIndexPath with length equal to 1

因此,现在indexPath的长度为2。是否可以将其更改为1? 我是否必须手动创建长度为1的其他NSIndexPath? 如果是这样,我将如何去做。

提前致谢

您将必须创建一个新的NSIndexPath 如果需要删除特定值,则必须在Swift中使用指针

let originalPath = NSIndexPath(indexes: [1,2,3], length: 3)
var indexes = UnsafeMutablePointer<Int>.alloc(originalPath.length)
originalPath.getIndexes(indexes) // This extracts values from NSIndexPath

var newValues = Array<Int>()
// Iterate over the pointer array
for val in UnsafeBufferPointer(start: indexes, count: originalPath.length) {
    // Determine values which you want in the new NSIndexPath
    newValues.append(val)
}

let newPath = NSIndexPath(indexes: newValues, length: newValues.count)

您还没有真正描述您要做什么以及为什么要这么做,但是

myIndexPath = myIndexPath.indexPathByRemovingLastIndex()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM