Reputation: 1680
My tableview app looks like this:
I don't know why that label1
is not working.
Here's how I done this:
I dragged a UITableViewController
and set it as initialViewController.
I set the UITableViewCell style as Custom
Then I set that UITableViewController's Custom Class
and UITableViewCell's
Then, I added some constraints:
Here's TableViewController.swift
:
import UIKit
class TableViewController: UITableViewController {
let arr = ["abc", "def", "ghi", "jkl", "mno"]
override func viewDidLoad() {
super.viewDidLoad()
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1 // This should more than one if you want to see the sections and rows in your tableview
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arr.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("item", forIndexPath: indexPath) as! TableViewCell
cell.label1.text = arr[indexPath.row]
return cell
}
}
And here's TableViewCell.swift
import UIKit
class TableViewCell: UITableViewCell {
@IBOutlet weak var label1: UILabel!
}
Anyone knows how to solve this? I really need to use custom cell!
P.S. I'm using Xcode 7 beta 5, Swift 2.0
Upvotes: 0
Views: 1927
Reputation: 421
try this
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
Upvotes: 5