You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swift旅行日记App问题:输入内容显示白色矩形而非文本求解决

问题解决:旅行日记App详情显示白色矩形的修复

你的问题出在List的行结构上:城市名称和详情被拆分成了List中两个独立的行,详情所在的行默认使用白色背景,而你给详情文本设置了白色字体,导致文字和背景颜色重叠,看起来就是白色矩形。

修复步骤

把城市名称和对应的详情包裹在同一个VStack中,作为List的单个行元素,这样就能继承你设置的.clear行背景,让白色文字正常显示。

修改后的List代码部分

List(landings, id: \.self) { landing in
    VStack(alignment: .leading) { // 用VStack包裹标题和详情,合并为单个行元素
        Text(landing).bold()
            .foregroundColor(.white)
            .onTapGesture {
                self.isEditing = true
                self.oldLandingName = landing
                self.newLandingName = landing
            }
        if let details = landingDetails[landing] {
            ForEach(details, id: \.self) { detail in
                Text(detail)
                    .foregroundColor(.white)
                    .padding(.top, 4) // 可选:添加间距优化布局
            }
        }
    }
    .listRowBackground(Color.clear) // 行背景设置移到外层VStack
    .listRowSeparatorTint(.blue)
}
.listStyle(.plain)

额外优化提示

  1. 添加页面的TextField占位符写"Where did you go? \(newLandingName)"会随输入内容变化,建议改成固定文本"Where did you go?"更合理。
  2. 编辑页面中$oldLandingName.wrappedValue写法冗余,直接用oldLandingName即可。

内容的提问来源于stack exchange,提问作者allanrulezdood

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 22:23:33