Reputation: 1115
I'm simply trying to display a tableview of names in the array of Smiles that I have set up. I need to declare my cell class "ClubCell" to extend to UITableViewCell, how would I go about doing this?
class SmileClub: UITableViewController {
var Smiles: [String] = ["Price Garrett", "Michael Bishop", "Tom Kollross", "Cody Crawford", "Ethan Bernath", "Alex Mlynarz", "Ryan Murphy", "Kelly Murphy", "Ryan Roshan", "Sean Ko"]
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> ClubCell
{
let cell: ClubCell = tableView.dequeueReusableCellWithIdentifier("ClubCell") as! ClubCell!
cell.Name.text = self.Smiles[indexPath.row] as String
return cell
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.Smiles.count
}
Upvotes: 0
Views: 1058
Reputation: 3040
Your ClubCell
is a subclass of UITableViewCell and it should look like:
class ClubCell:UITableViewCell
{
@IBOutlet weak var Name:UILabel!
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("ClubCell",forIndexPath:indexPath) as! ClubCell
cell.Name.text = self.Smiles[indexPath.row]
return cell
}
In this line cell.Name.text = self.Smiles[indexPath.row] as String
no need to downcast to String because your static array is already into String so change it to cell.Name.text = self.Smiles[indexPath.row]
Upvotes: 0
Reputation: 318934
The return value for the cellForRowAtIndexPath
method needs to be UITableViewCell
, not ClubCell
.
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell: ClubCell = tableView.dequeueReusableCellWithIdentifier("ClubCell") as! ClubCell!
cell.Name.text = self.Smiles[indexPath.row] as String
return cell
}
And make sure that your ClubCell
class extends UITableViewCell
.
It should be:
class ClubCell : UITableViewCell
Upvotes: 2