Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build an Interactive Story App with Swift Creating the User Interface Programmatically Displaying the Story

the story does't displayed when i press the 'Start your Adventure' button??

override func viewDidLoad() {

        if let page = page{

            artworkView.image = page.story.artWork
            let attributedString = NSMutableAttributedString(string: page.story.text)
            let paragraphStyle = NSMutableParagraphStyle()
            paragraphStyle.lineSpacing = 10

            attributedString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0, attributedString.length))

            storyLabel.text   = page.story.text

  override func viewWillLayoutSubviews() {

        artworkView.translatesAutoresizingMaskIntoConstraints = false // to cannot makes conflict in constraints when the new sub view added

        // image constraint
            artworkView.topAnchor.constraint(equalTo: view.topAnchor),
            artworkView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
            artworkView.rightAnchor.constraint(equalTo: view.rightAnchor),
            artworkView.leftAnchor.constraint(equalTo: view.leftAnchor)

        // label constraints
        storyLabel.numberOfLines = 0
        storyLabel.translatesAutoresizingMaskIntoConstraints = false

            storyLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16.0),
            storyLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16.0),
            storyLabel.topAnchor.constraint(equalTo: view.topAnchor, constant: -48.0)



Can I see the code that you have in the IBaction for when you press the button?


storyLabel.text   = page.story.text

sets the value for that label once the view loads, so basically this is the default text for the button as soon as it loads(assuming you're fine with this)