###前提・実現したいこと
スケジュールアプリを作成しています。
ユーザーが指定した「タイトル」「開始時刻」「終了時刻」をそれぞれ配列に追加し、
それぞれのデータをセルに表示させたい(開始時刻の昇順で)と思っております。
開始時刻を昇順で表示させるところで躓いております。
現在はとりあえずindexPath.rowで登録した順に表示するコードを書いています。
下記にcellForRowAtのソースコードを記します。
Swift ここにご自身が実行したソースコードを書いてください ``` func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TableViewCell func dateString(date: NSDate) -> String { let dateFormatter = DateFormatter() dateFormatter.calendar = NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian)! as Calendar! dateFormatter.locale = NSLocale.system dateFormatter.timeZone = NSTimeZone.system dateFormatter.dateFormat = "H:mm" let dateString: String = dateFormatter.string(from: date as Date) return dateString } var strBox = dateString(date: dateArray1[indexPath.row] as NSDate) var strBox2 = dateString(date: dateArray2[indexPath.row] as NSDate) let strCount: Int = strBox.characters.count let strCount2: Int = strBox2.characters.count if strCount < 5 { timeLabelText1 = " " + dateString(date: dateArray1[indexPath.row] as NSDate) + " " } else { timeLabelText1 = dateString(date: dateArray1[indexPath.row] as NSDate) + " " } if strCount2 < 5 { timeLabelText2 = " " + dateString(date: dateArray2[indexPath.row] as NSDate) } else { timeLabelText2 = " " + dateString(date: dateArray2[indexPath.row] as NSDate) } let attrText = NSMutableAttributedString(string: timeLabelText1 + ">>>" + timeLabelText2) attrText.addAttribute(NSForegroundColorAttributeName, value: UIColor.red, range: NSMakeRange(7, 3)) attrText.addAttribute(NSForegroundColorAttributeName, value: UIColor.white, range: NSMakeRange(0, 5)) attrText.addAttribute(NSForegroundColorAttributeName, value: UIColor.white, range: NSMakeRange(12, 5)) cell.timeLabel?.attributedText = attrText cell.titleLabel?.text = " " + titleArray[indexPath.row]! // 枠のカラー cell.titleLabel.layer.borderColor = UIColor.darkGray.cgColor // 枠の幅 cell.titleLabel.layer.borderWidth = 1.0 // 枠を角丸にする場合 cell.titleLabel.layer.cornerRadius = 10.0 cell.titleLabel.layer.masksToBounds = true return cell } ###試したこと ###補足情報(言語/FW/ツール等のバージョンなど) より詳細な情報
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。