【问题标题】:Error when I want to access a row via the indexPath in a tableViewController当我想通过 tableViewController 中的 indexPath 访问一行时出错
【发布时间】:2015-12-16 06:02:44
【问题描述】:

我正在制作一个聊天应用程序。我在通过 tableViewController 的 indexPath(row) 访问对象数组时遇到问题。它给了我一个错误:“无法下标'[AnyObject]?'类型的值”代码如下。我该如何解决这个问题?

var user1 = PFUser.currentUser()
var user2 = self.objects[indexPath.row] as! PFUser

【问题讨论】:

标签: swift uitableview swift2 xcode7 nsindexpath


【解决方案1】:

您可以将self.objects 的声明更改为:

var objects = Array<PFUser>()

并像这样使用它:

let user = self.objects[indexPath.row] as BusinessLocation!

由于你指定了类型,它不会认为它是AnyObject

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 2011-10-01
    • 1970-01-01
    相关资源
    最近更新 更多