Swift 以编程方式增加索引
如何以编程方式增加indexPath类型的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) 由
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的练习,因为问题中没有提供任何细节。