質問があります、よろしくお願い申し上げます。
解決したいこと
下記のコードでは、アプリに罫線が表示されずに困っています。
理想図
よろしくお願い申し上げます。
全コード import UIKit class ViewController: UIViewController, UITableViewDataSource { //tableViewを参照できるようにする @IBOutlet weak var tableView: UITableView! //Insert below the tableView IBOutlet var names = [String]() //ユーザーのアクションとプログラムを結びつける @IBAction func addName(sender: AnyObject) { let alert = UIAlertController(title: "New Name", message: "Add a new name", preferredStyle: .Alert) let saveAction = UIAlertAction(title: "Save", style: .Default, handler: { (action:UIAlertAction) -> Void in let textField = alert.textFields!.first self.names.append(textField!.text!) self.tableView.reloadData() }) let cancelAction = UIAlertAction(title: "Cancel", style: .Default) { (action: UIAlertAction) -> Void in } alert.addTextFieldWithConfigurationHandler { (textField: UITextField) -> Void in } alert.addAction(saveAction) alert.addAction(cancelAction) presentViewController(alert, animated: true, completion: nil) } //タイトルの設定とCellを毎回再利用する override func viewDidLoad() { super.viewDidLoad() title = "\"The List\"" tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell") } //テーブルの中のセクションの数を決める func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } //UITableViewのData Sourceを決める 変数namesの数を返す。 //変数cellに再利用するCellを入れて、Cellに入力された値をnamesに入れて返す。 func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return names.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell") cell!.textLabel!.text = names[indexPath.row] return cell! } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2015/11/13 18:54
2015/11/15 06:06
2015/11/16 08:01