ios - Swift 获取 tableview 数组计数并将其放置在 textview

标签 ios arrays json swift uitableview

你好,我有 tableview 和解析 json,我有 textview,我想将我的 tableview 项目计数添加到 textview 但给了我;

fatal error: unexpectedly found nil while unwrapping an Optional value

错误

我的代码在这里

var clientList = [String]()

let json = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers) as? NSArray

            if let parseJSON = json {

                self.clientList = parseJSON as! [String]
                self.clientsmessage.text = "You have \(self.clientList.count) client"

            }

最佳答案

看起来您的 self.clientsmessage 没有正确实例化,请检查该部分。

if self.clientsmessage != nil {
    self.clientsmessage.text = "You have \(self.clientList.count) client"
}

关于ios - Swift 获取 tableview 数组计数并将其放置在 textview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35383567/

相关文章:

javascript - 提取具有多个值的对象并使用 Javascript 传递它们

ios - IOS 7的currentInputMode替代

ios - 如何在 Firebase 中手动触发 screen_view 事件

ios - Apple Developer 注册的最佳实践

iphone - 为什么 revmob 广告闪烁?

java - 关于不可变列表(由 Arrays.asList() 创建)

c++ - 如何将字符串数组写入二进制文件?

iphone - 如何保护来自 iPhone 的 JSON 请求?

C++ 菜单和数组中的字符串搜索

c# - 如何在 JsonValue 中序列化 JsonPrimitive