RimhTyping字母和访问不当

时间:2018-10-05 00:58:34

标签: swift

我刚刚开始学习iOS开发。我有3个屏幕(启动,第二和主屏幕)。我有一个ViewController第二(屏幕)。我用CocaoPods安装了RimhTypingLetters库。我认为我安装正确,因为我可以访问库的方法,并且Xcode自动识别方法,但是当我只是尝试使用该库时,会出现此错误:

Thread 1: EXC_BAD_ACCESS (code=1, address=0x200000003)

我不需要任何按钮或其他东西来触发输入字母。我只想在屏幕加载时自动运行它。

Pod文件:

# 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'

第二速

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元素,这是为什么我需要使用一个函数?

1 个答案:

答案 0 :(得分:0)

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

  1. 找到您的视图控制器,然后在其中找到TextView元素并将其选中。

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