xcode - 字符串插值中出现意外的 ""字符错误

标签 xcode swift string-interpolation

由于某种原因,我无法使用表达式。我缺少什么? :( enter image description here

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath)
        // Configure the cell...
        if(indexPath.section == 0){

            cell.textLabel!.text =  searchActive == true ? "\(csFilter[indexPath.row].returnFullDescription())" : "\(subjectPerSection["CS"]![indexPath.row].returnFullDescription())";

        }
        else if( indexPath.section == 1){
            cell.textLabel!.text =  searchActive == true ? "\(seaFilter[indexPath.row].returnFullDescription())" : "\( subjectPerSection["SEA"]![indexPath.row].returnFullDescription())";
        }
        else if( indexPath.section == 2){
            cell.textLabel!.text =  searchActive == true ? "\(humFilter[indexPath.row].returnFullDescription())" : "\( subjectPerSection["HUM"]![indexPath.row].returnFullDescription())";
        }
        return cell
    }

最佳答案

看起来你的字符串中有引号。他们需要“逃离”才能工作。

例如...rSection[\"CS\"]![indexPa....

(我收回这句话。我回答得太快了。)

我建议将三元运算符 ?: 扩展为完整的“if”语句并使用中间变量,直到它正常工作,然后再将其折叠起来。

关于xcode - 字符串插值中出现意外的 ""字符错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34973658/

相关文章:

ios - 当某些文件夹名称更新时,XCode 项目中要更新什么文件?

xcode - 与屏幕截图和文本一起共享 URL

function - 为什么编译器以不同的方式对待闭包和局部函数?

swift - 如何设置 SKLabelNode 的对齐方式

javascript - Angular 2 App 中字符串插值的动态评估

ios - 如何下载 Vuforia 应用程序的数据集?

xcode - 在 Interface Builder 中使用 Storyboard 时如何更改 NSTableCellView 的高度

ios - Swift 问题中的 NSXMLDelegate

swift - 为什么 LocalizedStringKey 的行为取决于我是否将字符串插值传递给它的初始化程序?

css - LESS 类名字符串插值不起作用