-5

error when try to assign a string to the UITextView. coding as below:-

class ViewController: UIViewController{

        @IBOutlet weak var txtResult: UITextView!

     override func viewDidLoad() {
         super.viewDidLoad()

         txtResult.text = "ABC"
     }
}
Isaac Lim
  • 3
  • 4
  • 2
    Your Outlet is linked to Storyboard or Xib file? – Reinier Melian Aug 27 '17 at 15:52
  • 4
    What is the *error*? – luk2302 Aug 27 '17 at 15:52
  • 3
    "error when": What error? – Larme Aug 27 '17 at 15:52
  • error happen on coding txtResult.text = "ABC". – Isaac Lim Aug 27 '17 at 16:06
  • @Isacc Lim what is the error ? question is still same.Update your code with what error log says,that will help understand things better. – Tushar Sharma Aug 27 '17 at 16:08
  • capture from console --> libc++abi.dylib: terminating with uncaught exception of type NSException – Isaac Lim Aug 27 '17 at 16:10
  • @lsacc Lim can you show more code ? Are you sure you have all outlets correctly, and have given correct class to controller. – Tushar Sharma Aug 27 '17 at 16:12
  • hi, i add in my full coding. – Isaac Lim Aug 27 '17 at 16:18
  • 1
    Possible duplicate of [What does “fatal error: unexpectedly found nil while unwrapping an Optional value” mean?](https://stackoverflow.com/q/32170456/2227743) – Eric Aya Aug 27 '17 at 16:19
  • 1
    @IsaacLim Unless you can update your question with the complete error, no one can help you properly. The message you posted in an earlier comment is not sufficient. – rmaddy Aug 27 '17 at 16:41
  • "libc++abi.dylib: terminating with uncaught exception of type NSException –" That's missing half of the whole error message. If you don't give us the complete error message, every asnwers here will be pure guess. Maybe it will point out your real error, but you're clearly calling for luck. Because there is nothing wrong with your current code. – Larme Aug 27 '17 at 19:45

2 Answers2

1
  1. Go to your code and delete the @IBOutlet line of code that you created
  2. Delete this in Storyboard: enter image description here I think you have few referencing outlets there for 1 object. You need to have only 1. So better to remove all of them.
  3. Add new outlet again.
  4. It should work.
Tung Fam
  • 7,899
  • 4
  • 56
  • 63
  • thanks, but still got error. when run until that code, the xcode terminate. – Isaac Lim Aug 27 '17 at 16:08
  • 1
    can you please edit your question and add more info like: 1. show me your storyboard as i showed on screenshot and 2. the error itself. otherwise it's hard to guess – Tung Fam Aug 27 '17 at 16:25
0

Providing more error details might help to solve your issue. But you can still solve it by checking few things-:

1) Check for UITextView outlet in storyboard-:

enter image description here

2) Check if you have given correct class to controller . In my case it's UnderlineViewController check for yours. Your controller should have same class.

2.a) Go to storyboard click on controller and select identity inspector.

2.b) check class name.

enter image description here

Now add text in controller class-:

import UIKit

class UnderlineViewController: UIViewController {

    @IBOutlet weak var textViewData: UITextView!

    override func viewDidLoad() {
        super.viewDidLoad()
        textViewData.text = "Tushar"
        }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

OUTPUT-:

enter image description here

MAKE SURE YOU HAVE NO MORE THEN 1 OUTLET FOR ANY VIEW IN SIMILAR CONTROLLER.

Tushar Sharma
  • 2,839
  • 1
  • 16
  • 38