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

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

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

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

Q&A

解決済

1回答

971閲覧

Swift エラーの改善

vangogh---

総合スコア4

Swift

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

0グッド

0クリップ

投稿2022/01/11 09:38

アラーム機能を作成していく上で下の方のcase1でCannot convert return expression of type 'AlarmDeleteCell' to return type 'UITableViewCell'というエラーが出てしまいます。なぜかわからないでしょうか・・・?

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() }

Cannot find type 'UITableViewCell' in scopeというエラーも出てしまいます。

protocol AlarmDeleteCellDelegate { func alarmDeleteCell(delete:UITableViewCell) } class AlarmDeleteCell: UITableViewCell { var delegate:AlarmDeleteCellDelegate! @IBAction func deleteButton(_ sender: Any) { delegate.alarmDeleteCell(delete: self) } }

恐らく一つを改善するとどちらのエラーも改善すると思いますが、エラーの原因が分かりません・・・。よろしくお願いします。

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

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

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

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

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

hoshi-takanori

2022/01/11 10:25

AlarmDeleteCell.swift で import UIKit してますか? (import Foundation のままになってるとか?)
vangogh---

2022/01/11 10:27

完全に忘れてました!原因それでした!本当にありがとうございます!
vangogh---

2022/01/11 10:28

ベストアンサーにしたいので回答でご回答いただけますでしょうか・・・? 本当にありがとうございます!
guest

回答1

0

ベストアンサー

AlarmDeleteCell.swift で import UIKit してますか? (import Foundation のままになってるとか?)

投稿2022/01/11 10:29

hoshi-takanori

総合スコア7895

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問