スプリットビューコントローラがあり、ユーザーがテーブルビューでセルをクリックすると、2つの子ビューコントローラを切り替えるコンテナビューとセグメントコントロールを持つビューコントローラが表示されます。コレクションビューのセルを並べ替えることができません
最初の子ビューコントローラは、コレクションビューコントローラです。コレクションビューの各セルには単語があります。
ビューは次のようになります。ここでは
override func viewDidLoad() {
self.currentViewController = self.storyboard?.instantiateViewController(withIdentifier: "WordCollectionViewControllerID")
(self.currentViewController as! WordCollectionViewController).text = self.text
self.currentViewController?.view.translatesAutoresizingMaskIntoConstraints = false
self.addChildViewController(self.currentViewController!)
self.addSubview(subView: self.currentViewController!.view, toView: self.textContainerView)
self.currentViewController?.view.layoutIfNeeded()
self.currentViewController?.didMove(toParentViewController: self)
super.viewDidLoad()
}
func addSubview(subView: UIView, toView parentView: UIView) {
parentView.addSubview(subView)
var viewBindingsDict = [String: AnyObject]()
viewBindingsDict["subView"] = subView
parentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[subView]|", options: [], metrics: nil, views: viewBindingsDict))
parentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[subView]|", options: [], metrics: nil, views: viewBindingsDict))
}
:
は、私が(詳細ビューコントローラ、サブビューのコンテナから)このコードでプログラムで子ビューコントローラを追加しますセグメント化されたコントロールを持つ2つの子ビュー間の切り替えのコードです:@IBAction func changeChildViewController(_ sender: UISegmentedControl) {
if sender.selectedSegmentIndex == 0 {
let newViewController = self.storyboard?.instantiateViewController(withIdentifier: "WordCollectionViewControllerID")
(newViewController as! WordCollectionViewController).text = self.text
newViewController!.view.translatesAutoresizingMaskIntoConstraints = false
cycle(from: self.currentViewController!, to: newViewController!)
self.currentViewController = newViewController
print("Reorder")
} else {
let newViewController = self.storyboard?.instantiateViewController(withIdentifier: "NavigationControllerEditTextViewControllerID")
(newViewController?.childViewControllers[0] as! EditTextViewController).text = self.text
newViewController!.view.translatesAutoresizingMaskIntoConstraints = false
cycle(from: self.currentViewController!, to: newViewController!)
self.currentViewController = newViewController
print("Edit")
}
}
func cycle(from: UIViewController, to: UIViewController) {
from.willMove(toParentViewController: nil)
self.addChildViewController(to)
self.addSubview(subView: to.view, toView: self.textContainerView)
to.view.layoutIfNeeded()
from.view.removeFromSuperview()
from.removeFromParentViewController()
to.didMove(toParentViewController: self)
}
問題は、私がクリックしたときにテーブルビューセルとアプリがコレクションビューコントローラとコンテナビューを示すことである
override func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
// Swap values if sorce and destination
let change = textArray[sourceIndexPath.row]
textArray.remove(at: sourceIndexPath.row)
textArray.insert(change, at: destinationIndexPath.row)
// Save changes in Core Data
text?.reordered_text = textArray.joined(separator: " ")
(UIApplication.shared.delegate as! AppDelegate).saveContext()
collectionView.reloadData()
}
:私は私のカスタムCollectionViewControllerクラスの、このメソッドを実装しているセルを並べ替えることができるように
埋め込み、私は、セルを並べ替えることはできませんし、これを行うには、(セグメント化されたコントロールで)子を変更し、コレクションビューに戻る必要があります。
どうすればこの問題を解決できますか?
私は言語といくつかのミスを犯してしまった場合、私はイタリアの – ale00
あなたのtableView上で何をしているのです-didSelect? – Aks
私は何もしていませんtableView-didSelect @Aks – ale00