スケジュールアプリを開発しています。
Contentというクラスに、
「タイトル(変数title)」、「開始時刻(変数startDate)」、「終了時刻(endDate)」を定義しています。
そしてContentクラスを配列として扱っている変数sortedContentsがあります。
sortedContentsはAppDelegate.swiftで定義しています。
例えば下記のようにtableViewのcell.textLabelにtitle、startDate、endDateを表示していると仮定します。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") let delegate = UIApplication.shared.delegate as! AppDelegate cell?.textLabel?.textColor = UIColor.white cell?.textLabel?.text = delegate.sortedContents[indexPath.row].title + " / " + format.string(from: delegate.sortedContents[indexPath.row].startDate) + " / " + format.string(from: delegate.sortedContents[indexPath.row].endDate) return cell! }
これを、「startDate」の日付を条件にして要素を取り出し、それに付随した「title」と[endDate]もセットでtextLabelに表示したいのです。
例えば、sortedContent[]が下記のような要素を持っていると仮定します。
・1つ目
delegate.sortedContents[0]
title: "会議"
startDate: 2017-06-24 14:00:00
endDate: 2017-06-24 16:00:00
.
・2つ目
delegate.sortedContents[1]
title: "飲み会"
startDate: 2017-06-24 19:00:00
endDate: 2017-06-24 23:00:00
このような場合に、例えば、
startDateが2017-06-24 19:00:00の場合のみ、cell?.textLabel?.textへ代入する。
といった条件を与え、
cell?.textLabel?.textに
「飲み会 / 2017-06-24 19:00:00 / 2017-06-24 23:00:00」と表示したいのです。
どのようなコードを記述すれば実現できますでしょうか?
ご教示頂けますと幸いです。
下記にContentクラスの定義部分を記述しておきます。
// Content.swift import UIKit class Content: NSObject { var title: String = "" var startDate: Date = Date() var endDate: Date = Date() }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。