无法将'Int'类型的值转换为预期的参数类型'NSIndexSet'..?

时间:2015-11-09 10:10:34

标签: swift2

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "showView"
        {
            var upcoming: NewViewController = (segue.destinationViewController as? NewViewController)!
            let indexPath = self.tableView.indexPathForSelectedRow!
            let titleString = self.objects.objectsAtIndexes(indexPath.row) as? String 

            upcoming.titleString = titleString
            self.tableView.deselectRowAtIndexPath(indexPath, animated: true)
         }
    }

我收到以下错误

  

无法将'Int'类型的值转换为预期的参数类型'NSIndexSet'..

在我尝试将值转换为字符串的行中:

let titleString = self.objects.objectsAtIndexes(indexPath.row) as? String 

1 个答案:

答案 0 :(得分:1)

let titleString = self.objects.objectsAtIndexes(indexPath.row) as? String

您要求索引上的对象,但您真正想要的是对象 索引

你可以使用self.objects[indexPath.row]