【发布时间】:2016-03-26 05:47:01
【问题描述】:
我正在学习使用 Swift 和 Xcode 制作 IOS 程序。我一边看书一边看视频。我遇到了一个问题。我在视图控制器中创建了一个表视图。我知道如何指定行数以及文本标签中的内容。但是,我不知道如何删除 tableview 产生的额外行。我只有 4 行,但它显示了空白的额外行。
这是我的代码:
import UIKit /// imports the UIKit library
class MainScreenViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var MainScreenTableView: UITableView!
let myMenuOptions = [ "Instructions", "Create", "Open", "Send" ]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.MainScreenTableView.dataSource = self // self refers to the view controler we are in
self.MainScreenTableView.delegate = self /* dataSource means the view control provides the table with information */
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.myMenuOptions.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel!.text = myMenuOptions[indexPath.row]
return cell
}
谢谢
【问题讨论】:
标签: ios swift uitableview