Reputation: 4166
I followed this post and put inside my custom UITableViewCell SummaryCell
the UITableView detailTableView
But now I'm getting the error:
Type 'SummaryCell` does not conform to protocol `UITableViewDataSource`
If anyone could tell what I'm doing wrong & how to fix this I would greatly appreciate it!
Code for SummmaryCell
:
class SummaryCell: UITableViewCell, UITableViewDelegate, UITableViewDataSource{
@IBOutlet weak var dayOfWeek: UILabel!
@IBOutlet weak var totalSpent: UILabel!
@IBOutlet weak var totalSpentView: UIView!
@IBOutlet weak var heightOfMainView: NSLayoutConstraint!
@IBOutlet weak var detailTableView: UITableView!
var data: [Expense] = [Expense]()
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
detailTableView.delegate = self
detailTableView.dataSource = self
//create data array
let calendar = NSCalendar.currentCalendar()
let dateComponents = NSDateComponents()
dateComponents.day = 14
dateComponents.month = 5
dateComponents.year = 2015
dateComponents.hour = 19
dateComponents.minute = 30
let date = calendar.dateFromComponents(dateComponents)
data = [Expense(amountSpent: 60), Expense(amountSpent: 20, date: date!), Expense(amountSpent: 40, date: date!, function: Function.Social, category: Category.Fun, subcategory: Subcategory.Events)]
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("detailCell") as! DetailTableViewCell
return cell
}
}
What my summaryCell
looks like :
Upvotes: 0
Views: 421
Reputation:
To follow up to return false's answer, a cell should only be responsible for its own views. It shouldn't have a property for its tableView. It's generally a bad design for the cell to need to know or control anything about a view in its superview hierarchy.
Also if you consider the unlikely possibility that the reusable cell that happened to be the delegate were to be deinitialized, the tableView would no longer have a delegate.
Upvotes: 1
Reputation: 8942
It is generally considered bad practice to make your UITableViewCell
class conform to the UITableViewDataSource
and UITableViewDelegate
protocols.
I would strongly recommend to set these both to a view controller containing a table view and could imagine that this probably causes your error.
Upvotes: 3