我已将表格 View 设置为由两个数组填充。当它只是在 TableView 中时,我成功地做到了这一点,但并不是我将它放入 View Controller 中,没有显示任何信息。我不知道我做错了什么,我设置了 viewController,就像我对 tableviewcontroller 所做的那样。 应该发生的是,将创建一行并填充信息,并继续此操作,直到填充所有数据。 问题是没有显示任何数据。我不知道我在这里错过了什么。任何帮助,将不胜感激。
这是我的;
class MyViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var titleDate = ["Apple", "Apricot", "Banana", "Kiwi" , "Juniperberry" , "GhostBusteres"]
var descriptionDate = ["One", "Two", "Three", "4", "5", "6"]
@IBOutlet weak var myTableView: UITableView!
// MARK: - UIViewController lifecycle
override func viewDidLoad() {
super.viewDidLoad()
myTableView.editing = true
}
// MARK: - UITableViewDataSource
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return titleDate.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Coupon", forIndexPath: indexPath) as! CouponTableViewCell
cell.couponTitle.text = titleDate[indexPath.row]
cell.couponDescription.text = descriptionDate[indexPath.row]
cell.couponAnother.text = "Like a bloody storm"
return cell
}
func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
return .None
}
func tableView(tableView: UITableView, shouldIndentWhileEditingRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return false
}
func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
let movedObject = self.titleDate[sourceIndexPath.row]
titleDate.removeAtIndex(sourceIndexPath.row)
titleDate.insert(movedObject, atIndex: destinationIndexPath.row)
descriptionDate.removeAtIndex(sourceIndexPath.row)
descriptionDate.insert(movedObject, atIndex: destinationIndexPath.row)
NSLog("%@", "\(sourceIndexPath.row) => \(destinationIndexPath.row) \(titleDate)")
// To check for correctness enable: self.tableView.reloadData()
}
我还有将标签链接到变量的单元类,并且它也有效。
感谢您对此提供的任何帮助。
最佳答案
您需要设置UITableView
dataSource
和delegate
。
当您使用 UITableViewController
时,dataSource
和 delegate
已经设置好了。
参见 UITableView - Managing the Delegate and the Data Source文档。
关于ios - viewController 内的 tableview 中没有显示任何信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38240296/