ios - 获取行数但不打印

标签 ios json swift xcode uitableview

我有一个用 Swift 3 编写的程序,它从 REST API 获取 JSON 并将其附加到 TableView 中。

现在,我在让它在我的 Tableview 中打印时遇到了麻烦,但它确实理解我的计数函数。

所以,我猜我的数据在这里,但它只是没有正确返回它们:

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, HomeModelProtocal {

@IBOutlet weak var listTableView: UITableView!


func itemsDownloaded(items: NSArray) {
    feedItems = items
    self.listTableView.reloadData()
}

var feedItems: NSArray = NSArray()
var selectedLocation : Parsexml = Parsexml()

override func viewDidLoad() {
    super.viewDidLoad()


    self.listTableView.delegate = self
    self.listTableView.dataSource = self

    let homeModel = HomeModel()
    homeModel.delegate = self
    homeModel.downloadItems()
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cellIdentifier: String = "BasicCell"
    let myCell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)!
    let item: Parsexml = feedItems[indexPath.row] as! Parsexml
    myCell.textLabel!.text = item.title

    return myCell
}


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return feedItems.count 
}

override func viewDidAppear(_ animated: Bool) {
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}


}

您是否有机会看到我看不到的错误?

注意。我没有向表格行添加任何文本标签,但我想在自定义时不应该添加一个文本标签?

最佳答案

试试这个代码:

 override func viewDidLoad() {
   super.viewDidLoad()

  print(yourArrayName.count) // in your case it should be like this print(feedItems.count)
}

关于ios - 获取行数但不打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40191707/

相关文章:

ios - 如何在 objective-c 的 uitableview 中显示分组数据

ios - 从 SQL 数据库保存和加载图像

java - 从 Json 对象中提取数组

javascript - 将缺失值添加到分组数据中

ios - UIImageView 带有像 Facebook Messenger 一样的 subview

具有 dispatch_async/asynchronous 方法的 iOS Singleton API 管理器 : what's the implication?

swift - 手动添加 Snapkit 到 xcode

ios - MFMailComposeViewController的几个附件

ios - 仅请求始终授权,而不请求使用时授权

javascript - Angular js中的ajax重新加载