Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.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
Swift 以编程方式增加索引_Swift_Uicollectionview - Fatal编程技术网

Swift 以编程方式增加索引

Swift 以编程方式增加索引,swift,uicollectionview,Swift,Uicollectionview,如何以编程方式增加indexPath类型的var?例如,当前的indexPath是[0,44],我希望在特定操作之后,indexPath是[0,45]?,因为您使用的是集合视图,您似乎希望增加项属性 someIndexPath.item += 1 如果需要,还可以基于旧的indepath创建新的indepath: let newIndexPath = IndexPath(item: oldIndexPath.item + 1, section: oldIndexPath.section) 由

如何以编程方式增加indexPath类型的
var
?例如,当前的indexPath是[0,44],我希望在特定操作之后,indexPath是[0,45]?

,因为您使用的是集合视图,您似乎希望增加
项属性

someIndexPath.item += 1
如果需要,还可以基于旧的
indepath
创建新的
indepath:

let newIndexPath = IndexPath(item: oldIndexPath.item + 1, section: oldIndexPath.section)

由于您使用的是集合视图,因此似乎需要增加
属性

someIndexPath.item += 1
如果需要,还可以基于旧的
indepath
创建新的
indepath:

let newIndexPath = IndexPath(item: oldIndexPath.item + 1, section: oldIndexPath.section)

检查您没有超过该节中的行数
let rowsinssection=tableView.numberOfRows(第节:oldIndexPath.section);设newRow=min(rowsinssection-1,oldIndexPath.row+1);让newindexath=IndexPath(row:newRow,section:oldIndexPath.section)
@Carpsen90我留下了任何类型的验证作为OP的练习,因为问题中没有提供任何详细信息。请检查您没有超过该节中的行数
让rowsinssection=tableView.numberOfRows(第节:oldIndexPath.section);设newRow=min(rowsinssection-1,oldIndexPath.row+1);让newIndexPath=IndexPath(row:newRow,section:oldIndexPath.section)
@Carpsen90我留下任何类型的验证作为OP的练习,因为问题中没有提供任何细节。