Я создаю пользовательский делегат в своем классе TableViewCell
и вызываю его в классе tableView, но не знаю, почему эта ошибка наступает.Значение типа 'UITableViewCell?' не имеет делегата '
TableView Класс: -
//Cell For Row at indexPath
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
if (0 == indexPath.section)
{
let cell = tableView.dequeueReusableCell(withIdentifier: "FirstRowCell") as! FirstRowCell
cell.btnReview.addTarget(self, action: #selector(GotoReview), for: UIControlEvents.touchUpInside)
//cell.
return cell
}
else if (1 == indexPath.section)
{
let identifier = "TableCollectionCell"
var tableCollectionCell = tableView.dequeueReusableCell(withIdentifier: identifier)
if(tableCollectionCell == nil)
{
let nib:Array = Bundle.main.loadNibNamed("TableCollectionCell", owner: self, options: nil)!
tableCollectionCell = nib[0] as! TableCollectionCell
//Delegate
tableCollectionCell.delegate = self
}
return tableCollectionCell!
}
else
{
let identifier = "BrandImagesTableCell"
var brandImagesTableCell = tableView.dequeueReusableCell(withIdentifier: identifier)
if(brandImagesTableCell == nil)
{
let nib:Array = Bundle.main.loadNibNamed("BrandImagesTableCell", owner: self, options: nil)!
brandImagesTableCell = nib[0] as? BrandImagesTableCell
}
return brandImagesTableCell!
}
}
extension HomeViewController : CollectionViewCellTap
{
func didTapCollectionViewCell(indexPath: Int) {
let gotoCreateGroup = self.storyboard?.instantiateViewController(withIdentifier: "CreateGroupView") as! CreateGroupView
self.present(gotoCreateGroup, animated: true, completion: nil)
}
}
Вызов из класса TableViewCell: -
protocol CollectionViewCellTap
{
func didTapCollectionViewCell(indexPath : Int)
}
class TableCollectionCell: UITableViewCell {
@IBOutlet weak var collectionView: UICollectionView!
var delegate : CollectionViewCellTap?
override func awakeFromNib() {
super.awakeFromNib()
//collectionView cell
collectionView!.register(UINib(nibName: "CreateGroupCell", bundle: nil), forCellWithReuseIdentifier: "CreateGroupCell")
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
//Collection View
extension TableCollectionCell : UICollectionViewDataSource ,UICollectionViewDelegateFlowLayout
{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return 4
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CreateGroupCell", for: indexPath) as! CreateGroupCell
cell.groupName.text = ""
CreateCardView(viewCorner: cell.cardView)
if(0 == indexPath.row)
{
//cell.btnDotted.tag = indexPath.row
//cell.btnShare.tag = indexPath.row
cell.btnDotted.setImage(UIImage(named: "Info"), for: UIControlState.normal)
cell.btnShare.setImage(UIImage(named : "AddGroup"), for: UIControlState.normal)
}
else if(indexPath.row >= 1 && indexPath.row <= 3)
{
cell.btnDotted.isHidden = true
cell.btnShare.isHidden = true
cell.groupImage.image = UIImage(named: "group_dull_card.png")
}
else
{
}
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if (0 == indexPath.row) {
delegate?.didTapCollectionViewCell(indexPath: indexPath.row)
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 200, height: 150)
}
}
Я новичок в прошивке.
Вы можете поделиться об ошибкой? – PiyushRathi
эта ошибка только упомянутый в вопросе. – kishor0011
hey issue is 'TableCollectionCell', когда вы создаете объект ячейки, он не принимает в качестве объекта пользовательского класса TableCollectionCell. Просто добавьте как? TableCollectionCell при создании объекта. – PiyushRathi