UIView 中的 Swift TableView 不显示数据

编程入门 行业动态 更新时间:2024-10-24 18:21:46
本文介绍了UIView 中的 Swift TableView 不显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想创建一个页面,顶部应该有一张地图,底部应该有 5 行 tableview.所以我创建了 UIViewController 放置我的地图视图然后放置 TableView.我创建了 myViewController.swift 和 myTableViewCell.swift

I want to create a page which should have a map on the top and 5 row tableview at the bottom. So i created UIViewController put my Map View then put TableView. I created myViewController.swift and myTableViewCell.swift

但是当我在模拟器上尝试时,tableview 上没有显示数据.只有空单元格.我没有收到错误

But when i try on simulator no data showing on tableview. Only empty cells.I received no error

这是我的代码.谢谢

import UIKit import MapKit class myViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var mapView: MKMapView! var labels = ["some arrays"] var images = ["some image names in an array"] @IBOutlet weak var tableView: UITableView! override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return labels.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("mySegue", forIndexPath: indexPath) as! myTableViewCell cell.myCellLabel.text = labels[indexPath.row] cell.myCellImage.image = UIImage(named: images[indexPath.row]) return cell } }

推荐答案

试试这个:

override func viewDidLoad() { super.viewDidLoad() // Add this tableView.delegate = self tableView.dataSource = self }

更多推荐

UIView 中的 Swift TableView 不显示数据

本文发布于:2023-11-26 20:20:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635053.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   UIView   Swift   TableView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!