func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
print("WTF is this getting hit...")
let Cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! UITableViewCell
Cell.textLabel?.text = self.funlists[indexPath.row]
print("This better be getting hit")
return Cell;
}
for some reason this method isn't getting called.
i have set the following
uiTableView.delegate=self
uiTableView.dataSource=self
uiTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
and I have also included,
class viewUniversityList: UIViewController, UITableViewDelegate, UITableViewDataSource {
There might be several reason for this. Some of them are :
If you are using tableView in your ViewController file, then you should add the UITableViewDelegate
and UITableViewDelegate
delegates, like this :
class ViewController: UIViewController,UITableViewDelegate, UITableViewDelegate { ... }
If you have created a tableView
in code then you should do the following :
tableView.delegate = self tableView.dataSource = self tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "reuseIdentifier")
If that's all done, or you have create UITableView
through storyboard with a separate class which is a subClass of UITableView
, then you definitely need to define the following methods :
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {...}
~ func numberOfSectionsInTableView(tableView: UITableView) -> Int {...}
is optional as suggested by @rmaddy, but it's a good practice to define it.
delegate
property is not set on the tableView
? also tableView:numberOfRowsInSection:
should be implemented
you have to set your delegates and declare that you use those protocols
in file.m in didLoad
_table.delegate = self;
_table.dataSource = self;
in file.h when you declare the interface you have to add these protocols UITableViewDelegate
and UITableViewDataSource
Xcode will tell you which methods you must implement to respect the protocol.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.