You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS开发求助:displayMessage未解析及removeActivityIndicator无成员报错

解决SigninViewController的两个Swift编译错误

让我来帮你搞定这两个编译报错,本质都是因为你的SigninViewController类里缺少对应的方法定义导致的,咱们逐个解决:

1. 错误:Use of unresolved identifier 'displayMessage'

这个报错意味着编译器找不到名为displayMessage的方法或变量,大概率是以下两种情况:

  • 你还没在SigninViewController(或它的父类)里定义这个方法
  • 调用时的方法名拼写有误(Swift对大小写敏感哦)

解决方案

在SigninViewController类中添加这个方法的实现,比如一个常用的弹窗提示示例:

func displayMessage(title: String, message: String) {
    let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
    alert.addAction(UIAlertAction(title: "确认", style: .default))
    present(alert, animated: true)
}

如果这个方法是打算从父类继承的,请确认父类已经正确定义了该方法,且你的SigninViewController确实继承了这个父类。同时仔细核对调用时的拼写和方法名完全一致。

2. 错误:Value of type 'SigninViewController' has no member 'removeActivityIndicator'

这个报错逻辑和第一个一致,说明SigninViewController类中没有定义removeActivityIndicator方法。

解决方案

在类中添加这个方法的实现,假设你之前有添加活动指示器的逻辑,对应的移除方法可以参考下面的示例:

// 先声明一个存储活动指示器的属性(如果还没加的话)
var activityIndicator: UIActivityIndicatorView?

func removeActivityIndicator() {
    activityIndicator?.stopAnimating()
    activityIndicator?.removeFromSuperview()
    activityIndicator = nil
}

如果这个方法是写在某个扩展文件里的,请确保该扩展文件已经正确加入项目,且扩展是针对SigninViewController的。同样要检查方法名的拼写和大小写是否准确。

把这两个方法添加到你的SigninViewController类中后,编译错误应该就能消失啦。

内容的提问来源于stack exchange,提问作者Guna Desouza

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:52:22