swift - RimhTypingLetters 和错误访问
问题描述
我刚开始学习iOS开发。我有 3 个屏幕(启动、第二和主屏幕)。我有第二个(屏幕)的 ViewController。我用 CocooPods 安装了RimhTypingLetters库。我认为我确实安装正确,因为我可以访问库的方法并且 Xcode 自动识别方法但是当我只是尝试使用这个库时,我得到了这个错误:
Thread 1: EXC_BAD_ACCESS (code=1, address=0x200000003)
我不需要任何按钮或其他东西来触发输入字母。我只想在加载屏幕时自动运行它。
豆荚文件:
# Uncomment the next line to define a global platform for your project
platform :ios, '12.0'
target 'MyApp' do
pod 'RimhTypingLetters'
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for MyApp
end
workspace 'MyApp'
二.swift
import UIKit
import RimhTypingLetters
class Second: UIViewController {
@IBOutlet weak var textView1: TypingLetterUITextView!
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.asyncAfter(deadline: .now() + 7) {
let main = UIStoryboard(name: "Main", bundle: nil)
let mainVC = main.instantiateViewController(withIdentifier: "mainVC")
self.present(mainVC, animated: true, completion: nil)
}
typeTheText()
}
func typeTheText() {
let message = "Something.."
self.textView1.typeText(message) {
print("printed")
}
}
}
另外我不明白为什么我不能直接访问 viewDidLoad 之外的 UI 元素,我的意思是为什么我需要使用函数?
解决方案
所以这就是问题所在,您已将您更改为视图控制器UITextView
中的实例TypingLetterUITextView
,但尚未在界面构建器中将其设置为这种类型。为此,您需要在main.storyboard
文件中执行以下步骤:
找到您的视图控制器,然后在
TextView
那里找到元素并选择它。选择身份检查员,然后输入
TypingLetterUITextView
类名。
推荐阅读
- php - PHPUnit 返回“数据集 #0 无效。” 与数据提供者
- python - tkinter 类中的事件,未定义函数名
- swift - 只有弱者和无主的自己?
- c# - 需要解析 mime 内容
- c# - 微软是否有可能像在 UWP 之外的 Windows 中一样发布适用于 MacOS 和 Linux 的 .Net 框架版本?
- javascript - 将输入从 prompt() 传输到文本字段
- sas - SAS中的多个do循环
- tcl - 使用TCL ldap包修改用户AD密码
- laravel - 如何在循环中显示一次值
- python - Strange behavior of networkx draw