首页 > 解决方案 > 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 元素,我的意思是为什么我需要使用函数?

标签: swift

解决方案


所以这就是问题所在,您已将您更改为视图控制器UITextView中的实例TypingLetterUITextView,但尚未在界面构建器中将其设置为这种类型。为此,您需要在main.storyboard文件中执行以下步骤:

  1. 找到您的视图控制器,然后在TextView那里找到元素并选择它。

  2. 选择身份检查员,然后输入TypingLetterUITextView类名。


推荐阅读