ios - viewController 内的 tableview 中没有显示任何信息

标签 ios uitableview uiviewcontroller swift2

我已将表格 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 dataSourcedelegate
当您使用 UITableViewController 时,dataSourcedelegate 已经设置好了。
参见 UITableView - Managing the Delegate and the Data Source文档。

关于ios - viewController 内的 tableview 中没有显示任何信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38240296/

相关文章:

ios - 如何关闭使用 presentModalViewController : 打开的 View Controller

ios - 如何在 UIButton 的左侧和右侧放置文本

ios - 快速调用方法(方法在下一行之前没有完成)

ios - 在导航 Controller xcode 中添加 "Sub" View

ios - 如何在不重新加载所有 UITableView 数据的情况下更新特定 UITableViewCell 中的标签?

ios - 如何在消息应用程序中创建撰写栏按钮项目

如果在 JS 中初始化,iOS JSON Store 打开失败

ios - 如何创建一个无需应用商店更新即可远程更新的 View

ios - 选择 x 编号来自长数组的项目并在表格 View 中滚动显示更多

ios - 确定是否因为子模态外观而调用 viewWillDisappear