【发布时间】:2017-04-02 21:45:27
【问题描述】:
我有一个[Hashtag] 数组。 Hashtag NSObject 只保存了一个 hashtagName 的变量,即String?。一个数组是类别数组,另一个是时尚数组。我想要的是当我在我的 didSelectItemAtIndexPath 方法中点击某个 indexPath 时,我想将 fashionArray 插入到所选索引处的 categoriesArray 中。我遇到的问题是它需要一个字符串数组而不是一个标签数组。我如何实现这一目标?多谢你们。代码如下:
import UIKit
class Hashtag: NSObject {
var hashtagName: String?
}
private let reuseIdentifier = "Cell"
class HashtagView: UICollectionViewController, UICollectionViewDelegateFlowLayout {
var categoriesArray = [Hashtag]()
var fashionArray = [Hashtag]()
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.tintColor = .white
navigationItem.title = "Hashtag"
self.collectionView?.backgroundColor = .white
self.collectionView?.register(HashtagCell.self, forCellWithReuseIdentifier: reuseIdentifier)
self.collectionView?.contentInset = UIEdgeInsetsMake(10, 0, 0, 0)
handleFetchCategories()
handleFetchFashionHashtags()
}
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if indexPath.item == 1 {
// insert here
self.categoriesArray.insert(fashionArray[indexPath.item].hashtagName, at: 1)
print(categoriesArray)
}
}
【问题讨论】:
-
这不是your previous question的转贴吗?为什么还有一个问题?为什么不编辑你的另一个?
-
@rmaddy 我显然是一个新手,在回答帮助我的编程之后......为什么这样的工作值得?
-
是否是新手无关紧要。这个网站以某种方式运作。本网站不接受为了获得更多关注而转发问题。您应该做的正确的事情是根据需要编辑您之前的问题以使其更清晰。
标签: arrays swift swift3 uicollectionview collectionview