1
도청 될 때로드 할 테이블 뷰의 셀에 해당하는 VC
을 얻으려고합니다. indexPath
을 selectedIndexPath
으로 설정하고 컬렉션보기에서 segue를 설정 한 다음 tableView에서 사용하지만 오류가 발생했습니다. 여기에 코드가 있습니다.UICollectionViewController에서 선택된 인덱스 경로에서 UITableViewController를로드하는 중
import UIKit
private let reuseIdentifier = "profileCell"
class CompanyCollectionViewController: UICollectionViewController {
//MARK: - View Did Load
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
}
// MARK: UICollectionViewDataSource
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return stuff.company.count
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! ProfileCollectionViewCell
cell.profileImageView.image = UIImage(named: stuff.company[indexPath.row]["image"]!)
return cell
}
//MARK: - Prepare For Segue
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "profileSegue" {
let profileVC = segue.destinationViewController as!
MyProfileTableViewController
let cell = sender as! UICollectionViewCell
let indexPath = collectionView?.indexPathForCell(cell)
profileVC.selectedIndexPath = indexPath
}
}
}
하고 collectionView 경우 다음
import UIKit
class MyProfileTableViewController: UITableViewController {
//MARK: - View Did Load
override func viewDidLoad() {
super.viewDidLoad()
}
//MARK: - Table View Data Source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if let indexPath = selectedIndexPath {
let row = stuff.company[indexPath.row]
let cell = tableView.dequeueReusableCellWithIdentifier("myProfileCell", forIndexPath: indexPath) as! MyProfileTableViewCell
cell.heroImageView.image = UIImage(named: row["image"]!)
title = row["name"]
cell.nameLabel.text = row["name"]
cell.statusLabel.text = row["description"]
return cell
} else {
let cell = tableView.dequeueReusableCellWithIdentifier("myProfileCell", forIndexPath: indexPath) as! MyProfileTableViewCell
cell.heroImageView.image = UIImage(named: stuff.profile["profile image"]!)
title = stuff.profile["name"]
cell.nameLabel.text = stuff.profile["name"]
cell.statusLabel.text = stuff.profile["status"]
return cell
}
}
//MARK: - Variables
var selectedIndexPath: NSIndexPath?
} 내가 볼
무엇이 오류입니까? – Lytic
*** 캐치되지 않은 예외 'NSInternalInconsistencyException'으로 인해 응용 프로그램 종료, 이유 : '잘못된 색인 경로에서 rect 요청 – Androoo