ios - 如何从 TableViewCell 上的自定义 CollectionViewCell 推送 VC?
<p><p>我有一个 <code>tableView</code> 和 Cell,在 Cell 上我有一个 <code>collectionView</code> 并在上面显示一些内容。</p>
<p>我想发送选择 <code>indexPath</code> 的链接。</p>
<p>我想从 <code>TableViewCell</code> 上的自定义 <code>CollectionViewCell</code> 推送/呈现我的 View 。</p>
<pre><code>class secondTopicTableViewCell: UITableViewCell {
@IBOutlet weak var relatedCustom: UICollectionView!
var relArray= NSArray()
func loadArray(arr: NSArray) {
self.relArray = arr
self.relatedCustom.reloadData()
}
}
extension secondTopicTableViewCell : UICollectionViewDataSource {
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return relArray.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("collection", forIndexPath: indexPath) as! relatedCollectionViewCell
let info = self.relArray.objectAtIndex(indexPath.row) as! specificTopicInfo
cell.showInfo(info)
return cell
}
}
extension secondTopicTableViewCell : UICollectionViewDelegate {
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let relatedTopic =self.relArray.objectAtIndex(indexPath.row)as! specificTopicInfo
let str= relatedTopic.relatedLink!
print(str)
}
}
class relatedCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var relatedLabel: UILabel!
func showInfo(info: specificTopicInfo) {
relatedLabel.backgroundColor = UIColor.grayColor()
relatedLabel.text = info.relatedTitle
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您只需要使用与 Tableview 控件相同的 <strong>didSelectItemAtIndexPath</strong> 进行导航。
将导航代码写入 Collectionview 的 <strong>didSelectItemAtIndexPath</strong></p></p>
<p style="font-size: 20px;">关于ios - 如何从 TableViewCell 上的自定义 CollectionViewCell 推送 VC?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/39849611/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/39849611/
</a>
</p>
页:
[1]