###前提・実現したいこと
ここに質問したいことを詳細に書いてください
(例)PHP(CakePHP)で●●なシステムを作っています。
■■な機能を実装中に以下のエラーメッセージが発生しました。
Xcodeでswiftを使って世界時計のアプリを作ろうと思っているのですが、画面上にTable Viewを配置してその中に国名を表示したボタンをいくつも作ってそこの現在の時刻を表示したいです。
前にストップウォッチのアプリを作って、その時もTable Viewを配置してボタンを押した時にその時のタイムを次々記録していくものを作りました。iPhoneに最初から入っているアプリみたいな感じです。そこで、ストップウォッチのアプリを今回作ろうと思っているアプリに利用しようと思ったのですが、Table Viewにボタンを配置したことがないので、やり方が全くわかりません。下記に載せたのはそのストップウォッチのアプリです。ボタンなどはプログラム上で作成せずにstoryboardで作成してから結びつけました。ご回答よろしくお願いします。
###発生している問題・エラーメッセージ
エラーメッセージ
###該当のソースコード
ここにご自身が実行したソースコードを書いてください import UIKit class SecondViewController: UIViewController { //タイムラベル @IBOutlet weak var Timelabel: UILabel! //スタートボタン @IBOutlet weak var startButton: UIButton! //スプリットボタン @IBOutlet weak var splitButton: UIButton! //リセットボタン @IBOutlet weak var resetButton: UIButton! //テーブル @IBOutlet weak var tableView1: UITableView! var timeArray:[String] = [] var countNum = 0 var timerRunning = false var timer = NSTimer() override func viewDidLoad() { super.viewDidLoad() splitButton.enabled = false // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func update() { countNum += 1 timeFormat(countNum) } func timeFormat(countNum:Int) { let ms = countNum % 100 let s = (countNum - ms) / 100 % 60 let m = (countNum - s - ms) / 6000 % 3600 self.Timelabel.text = String(format: "%02d:%02d.%02d", m, s, ms) } //スタートボタン押された時 @IBAction func startTimer(sender: AnyObject) { if timerRunning == false { startButton.setImage(UIImage(named: "stop.png"), forState: UIControlState.Normal) timer = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector: #selector(SecondViewController.update), userInfo: nil, repeats: true) timerRunning = true resetButton.enabled = false splitButton.enabled = true } else{ timer.invalidate() startButton.setImage(UIImage(named: "start.png"), forState: UIControlState.Normal) timerRunning = false resetButton.enabled = true splitButton.enabled = false } } //ストップボタン押された時 @IBAction func stopTimer(sender: AnyObject) { if timerRunning == true { timeArray.insert(Timelabel.text!, atIndex: 0) tableView1.reloadData() } } //リセットボタン押された時 @IBAction func resetTimer(sender: AnyObject) { countNum = 0 Timelabel.text = "00:00.00" timeArray = [] tableView1.reloadData() startButton.setImage(UIImage(named: "start.png"), forState: UIControlState.Normal) } /// セルの個数を指定するデリゲートメソッド(必須) func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return timeArray.count } /// セルに値を設定するデータソースメソッド(必須) func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { // セルを取得する let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("tableCell", forIndexPath: indexPath) // セルに表示する値を設定する let label2 = tableView.viewWithTag(1) as! UILabel label2.text = "\(timeArray[indexPath.row])" return cell } } ###試したこと 課題に対してアプローチしたことを記載してください ###補足情報(言語/FW/ツール等のバージョンなど)
あなたの回答
tips
プレビュー