代码之家  ›  专栏  ›  技术社区  ›  Sina Hamzezadeh

源文件中的Swift编辑器占位符

  •  4
  • Sina Hamzezadeh  · 技术社区  · 8 年前

    您好,swift错误“源文件中的swift编辑器占位符”有问题 这是我的密码

    public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
    
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: <#T##IndexPath#>) as! CustomBrandCell
    
        let brandImage: UIImage = UIImage(named: self.brands[indexPath.row].name)!
    
        cell.brandImageView.image = brandImage
    
        return cell
    }
    
    3 回复  |  直到 8 年前
        1
  •  16
  •   ntoonio    7 年前

    我多次发现同样的问题。但他们都没有给出我想要的答案。

    你明白了吗 Placeholder in source file 当您的代码中有其中一个(其中显示蓝色背景的“字符串”)时。

    Image

    占位符是给我们程序员的。它说“这里应该有一个字符串类型的值”。您可以单击它并开始键入,只需将其替换为变量名。也可以按tab键自动选择下一个占位符。这在调用具有多个参数(因此具有多个占位符)的函数时非常有用。

    占位符实际上只是普通文本(<#T##Strign#>),但XCode将其“翻译”成它的样子。

    在您的情况下,错误在第三行。

    ...withReuseIdentifier: "Cell", for: <#T##IndexPath#>) as! CustomBrandCell
    

    如你所见 <#T##IndexPath#> 是一个占位符,就像我前面提到的普通文本一样。你可能希望这样 indexPath

        2
  •  5
  •   Techie    5 年前

    尝试cmd+shift+k清理项目并再次运行代码。这为我解决了这个问题。

        3
  •  0
  •   Museer Ahamad Ansari    8 年前

    试试这个。希望能解决你的问题

    public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
    
          // get a reference to your storyboard cell
         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath as IndexPath) as! CustomBrandCell
    
         let brandImage: UIImage = UIImage(named: self.brands[indexPath.row].name)!
    
         cell.brandImageView.image = brandImage
    
         return cell
    }