0

I am developing an IOS app using swift language in which I want to segue from uitableview's row to uitextview to show some text and I want to use attributed text property of uitextview but its not working.How to do that?

Waqar Khalid
  • 119
  • 1
  • 12
  • A segue takes you from one UIViewController to another. You can have a UITableView inside of a viewController where the viewController is the delegate of the tableView. It sounds like you are not properly describing what you want. Edit your question to include what you have in the didSelectRow delegate method. Also describe in plain words what you want to happen when you select a row. Do you leave and go to a new page or does something on that page change? – Andrew McKinley Apr 07 '16 at 18:20
  • i am using static rows and when the row is selected it goes to a new view controller where I used a uitextview to show some text.I only wants to use attributes for that text to be displayed by programming since the text changes which each different row so I can not place text in the text attribute of uitextview at storyboard. – Waqar Khalid Apr 07 '16 at 18:24

1 Answers1

0

First of all, you can't segue to a UITextView; you can segue only to another view controller. But maybe you meant to say that your segue goes to a view controller with a UITextView in it. If so, then control-drag a segue from your table view cell to the other view controller, and give the segue an identifier. Then, in your table view controller, implement:

func prepareForSegue(_ segue: UIStoryboardSegue, sender sender: AnyObject?) {
    if segue.identifier == "the-segue-id-that-you-put-in-your-storyboard" {
        // Cast your destination view controller to the specific type
        if let destinationVC = segue.destination as? <your-view-controller-type> {
            destinationVC.textView.attributedText = <your-string>
        }
    }
}
NRitH
  • 13,441
  • 4
  • 41
  • 44
  • Yes you are right I want the same thing but it will be more helpful if you tell how to write attributed string for the last line you have written since I can only assign a string of type NSattributedstring to destinationvc.textview.attributedText. – Waqar Khalid Apr 07 '16 at 18:28
  • It's funny you should ask, since I have [another StackOverflow answer that discusses just that](http://stackoverflow.com/questions/24666515/how-do-i-make-an-attributed-string-using-swift/24666710#24666710)... – NRitH Apr 07 '16 at 18:47
  • i am facing error at the line destinationvc.textview.attributedText. The error is " fatal error: unexpectedly found nil while unwrapping an Optional value". – Waqar Khalid Apr 07 '16 at 19:09
  • Make sure that your `textView`'s outlet is properly set to the text view instance in your storyboard. – NRitH Apr 07 '16 at 19:11
  • its set properly when i use destinationvc.text = "something" the text is shown but when I used destinationvc.textview.text = "something" it shows this error. – Waqar Khalid Apr 07 '16 at 19:16
  • So your destination view controller must have a `text` attribute that sets the text view's text. – NRitH Apr 07 '16 at 19:35
  • Yeah got that and thanks for great help.Can I PM you when I need help in future?please give me your facebook id or something where i can.It will be so kind of you. – Waqar Khalid Apr 07 '16 at 20:01