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

Eureka表单TextAreaRow粘贴内容时前置空格问题的解决方法

解决Eureka TextAreaRow粘贴内容自动添加开头空格的问题

这个问题的根源是Eureka的TextAreaRow底层依赖的UITextView默认开启了智能插入删除功能(smartInsertDeleteType属性默认值为.default),粘贴内容时会自动在开头补空格适配上下文。要解决这个问题,直接禁用该智能行为即可:

在TextAreaRow的配置闭包里,访问其底层的textView对象,将smartInsertDeleteType设置为.no:

import UIKit
import Eureka

class MyViewController: FormViewController {
    func setupEurekaForm() {
        form
        +++ Section("TEXTFIELDS")
        <<< TextAreaRow() {
            $0.value = "Test text"
            // 禁用智能插入删除,阻止粘贴时自动加空格
            $0.textView.smartInsertDeleteType = .no
        }
    }
}

如果项目里有多个TextAreaRow需要这个设置,可以全局配置一次,避免重复写代码:

// 在项目启动逻辑里(比如AppDelegate/SceneDelegate)添加全局配置
TextAreaRow.defaultRowInitializer = { row in
    row.textView.smartInsertDeleteType = .no
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 16:30:58