質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

977閲覧

このソースコードにおけるエラーの対処方法が分かりません。

vangogh---

総合スコア4

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2022/01/10 12:13

前提・実現したいこと

アラーム機能を作りたいです。

発生している問題・エラーメッセージ

Cannot find type 'AlarmDeleteCell' in scope
Cannot find type 'AlarmDeleteCellDelegate' in scope
Editor placeholder in source file
3つのエラーが出ていますが解決できません・・・。

import文などは省略しています。 class AlarmAddVC: UIViewController ,UITableViewDelegate,UITableViewDataSource{ @IBOutlet weak var datePicker: UIDatePicker! @IBOutlet weak var tableView: UITableView! var delegate:AlarmAddDelegate! var alarmTime:AlarmTimeArray = AlarmTimeArray() var isEdit: Bool = false var titleText = ["Repeat","Label","Sound"] override func viewDidLoad() { super.viewDidLoad() datePicker.date = alarmTime.date registerCell(cellName: "AlarmSnoozeCell") registerCell(cellName: "AlarmAddCell") registerCell(cellName: "AlarmDeleteCell") tableView.tableFooterView = UIView() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) if let indexPathForSelectedRow = tableView.indexPathForSelectedRow { tableView.deselectRow(at: indexPathForSelectedRow, animated: true) } } //cell登録 func registerCell(cellName:String){ tableView.register(UINib(nibName: cellName, bundle: nil), forCellReuseIdentifier: cellName) } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { switch section { case 0: return 4 case 1: return 1 default: return 0 } } func numberOfSections(in tableView: UITableView) -> Int { return isEdit ? 2:1 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { switch indexPath.section { case 0: switch indexPath.row{ case 0: let cell = tableView.dequeueReusableCell(withIdentifier: "AlarmAddCell") as! AlarmAddCell cell.titleLabel.text = titleText[indexPath.row] cell.subTitleLabel.text = alarmTime.repeatLabel return cell case 1: let cell = tableView.dequeueReusableCell(withIdentifier: "AlarmAddCell") as! AlarmAddCell cell.titleLabel.text = titleText[indexPath.row] cell.subTitleLabel.text = alarmTime.label return cell case 2: let cell = tableView.dequeueReusableCell(withIdentifier: "AlarmAddCell") as! AlarmAddCell cell.titleLabel.text = titleText[indexPath.row] cell.subTitleLabel.text = "Default" cell.selectionStyle = .none return cell case 3: let cell = tableView.dequeueReusableCell(withIdentifier: "AlarmSnoozeCell") as! AlarmSnoozeCell cell.delegate = self cell.snoozeSwitch.isOn = alarmTime.snooze return cell default: break } case 1: let cell = tableView.dequeueReusableCell(withIdentifier: "AlarmDeleteCell") as! AlarmDeleteCell cell.delegate = self return cell default: break } return UITableViewCell() } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { switch indexPath.section { case 0: switch indexPath.row { case 0: self.performSegue(withIdentifier: "showRepeat", sender: nil) case 1: performSegue(withIdentifier: "showLabel",sender: nil) break case 2:break default:break } default: break } } public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { if section == 1 { return 50 }else{ return 0 } } //アラーム設定時間を保存 @IBAction func saveButton(_ sender: Any) { alarmSet() delegate.AlarmAddVC(alarmAdd: self, alarmTime: alarmTime) dismiss(animated: true, completion: nil) } //スヌーズ設定 func setCategories(){ let snoozeAction = UNNotificationAction( identifier: "snooze", title: "Snooze 5 Minutes", options: [] ) let noAction = UNNotificationAction( identifier: "stop", title: "stop", options: [] ) var alarmCategory:UNNotificationCategory! if alarmTime.snooze { alarmCategory = UNNotificationCategory( identifier: "alarmCategory", actions: [snoozeAction, noAction], intentIdentifiers: [], options: []) }else{ alarmCategory = UNNotificationCategory( identifier: "alarmCategory", actions: [], intentIdentifiers: [], options: []) } UNUserNotificationCenter.current().setNotificationCategories([alarmCategory]) } //通知設定 func setNotificationC(day:String, repeats:Bool){ let content = UNMutableNotificationContent() content.title = alarmTime.label content.sound = UNNotificationSound.default content.categoryIdentifier = "alarmCategory" var dateComponents = DateComponents() if !day.isEmpty { dateComponents.weekday = weekDay(day: day) } dateComponents.hour = Calendar.current.component(.hour, from: datePicker.date) dateComponents.minute = Calendar.current.component(.minute, from: datePicker.date) let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: repeats) let request = UNNotificationRequest(identifier: alarmTime.uuidString+day, content: content, trigger: trigger) UNUserNotificationCenter.current().add(request) { (error) in if let error = error { print(error.localizedDescription) } } alarmTime.date = datePicker.date } //アラート設定 func alarmSet(){ removeAlarm(identifiers: alarmTime.uuidString) let shortWeekday = DateFormatter().shortWeekdaySymbols! for i in shortWeekday { removeAlarm(identifiers: alarmTime.uuidString+i) } if alarmTime.week.isEmpty { setCategories() setNotificationC(day:"", repeats: false) }else{ for i in alarmTime.week { setCategories() setNotificationC(day: i, repeats: true) } } } //アラート設定削除 func removeAlarm(identifiers:String){ UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [identifiers]) } //キャンセル @IBAction func cancelButton(_ sender: Any) { delegate.AlarmAddVC(alarmCancel: self) dismiss(animated: true, completion: nil) } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { switch segue.identifier { case "showRepeat": guard let nextVC:AlarmRepeatVC = segue.destination as? AlarmRepeatVC else {return} nextVC.delegate = self nextVC.selectDay = alarmTime.week case "showLabel": guard let nextVC:AlarmAddLabelVC = segue.destination as? AlarmAddLabelVC else {return} nextVC.delegate = self nextVC.text = alarmTime.label default: return } } } extension AlarmAddVC:AlarmRepeatVCDelegate { func AlarmRepeatVC(addRepeat: AlarmRepeatVC, week: [String]) { alarmTime.week = [] alarmTime.repeatLabel = "" alarmTime.week += week if alarmTime.week.count == 1 { alarmTime.repeatLabel = "Every"+alarmTime.week[0] }else if alarmTime.week.isEmpty { alarmTime.repeatLabel = "Never" }else if alarmTime.week.count == 7{ alarmTime.repeatLabel = "Every day" }else{ let shortWeekday = DateFormatter().shortWeekdaySymbols! for i in alarmTime.week { if alarmTime.repeatLabel != "" { alarmTime.repeatLabel += "," } alarmTime.repeatLabel += shortWeekday[weekDay(day: i)] } } tableView.reloadData() } } extension AlarmAddVC:AlarmAddLabelDelegate { func alarmAddLabel(labelText: AlarmAddLabelVC, text: String) { alarmTime.label = text tableView.reloadData() } } extension AlarmAddVC:AlarmSnoozeCellDelegte{ func alarmSnoozeCell(swichOn: AlarmSnoozeCell, On: Bool) { alarmTime.snooze = On } } extension AlarmAddVC:AlarmDeleteCellDelegate{ func alarmDeleteCell(delete: UITableViewCell) { delegate.AlarmAddVC(alarmDelete: self,alarmTime:alarmTime) dismiss(animated: true, completion: nil) } } ### 該当のソースコード

Swift

### 試したこと 調べてエラーの内容は理解できたのですが、このソースコードにおける解決方法が分かりませんでした。 お力をお貸しください。よろしくお願いします。 ### 補足情報(FW/ツールのバージョンなど) エラーは以下の3文に出ています。 let cell = tableView.dequeueReusableCell(withIdentifier: "AlarmDeleteCell") as! AlarmDeleteCell extension AlarmAddVC:AlarmDeleteCellDelegate{ func alarmDeleteCell(delete: UITableViewCell) {

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

元のコードが記載されているっぽいサイトにgithubへのリンクがあるようでした。

github

swiftでiPhone標準の時計アプリを作ろう 完成コード アラーム-Geminiのプログラミング記録

元のサイトのページには記載されていないようでしたが、GitHubにはprotocolとclassが存在するようでした。

swift

1protocol AlarmDeleteCellDelegate { 2 func alarmDeleteCell(delete:UITableViewCell) 3} 4 5 6class AlarmDeleteCell: UITableViewCell { 7 var delegate:AlarmDeleteCellDelegate! 8 @IBAction func deleteButton(_ sender: Any) { 9 delegate.alarmDeleteCell(delete: self) 10 } 11}

https://github.com/Gemini-blog/clock-app/blob/master/clockApp/Alarm/AlarmDeleteCell.swift


Editor placeholder in source file

このエラー?はプレースホルダーを入力するとか、それでダメならプロジェクトをクリーンしたら消えるでしょうか。

投稿2022/01/10 13:59

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

vangogh---

2022/01/10 14:22

ありがとうございます!!!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問