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 Delegates in Swift 2 Delegation in iOS Modifying Appearance With Delegates

Eric Aichele
Eric Aichele
4,710 Points

Broken in XCode 7.3.1

Getting two errors in the downloaded files in the newest version of XCode(7.3.1). Can we get a support document for this? This is one of many where I've seen this with zero documentation on how to fix it. Please post some documentation.

Michael Hulet
Michael Hulet
47,912 Points

I'm running Xcode 7.3.1 Build 7D1012 (which is the latest), and a fresh download of the project files produce no errors and 1 warning that can be fixed by just pressing the "Update Settings" button on the warning. What're you seeing?

Jonathan Bachelor
Jonathan Bachelor
5,880 Points

I am also using XCode 7.3.1, and get a runtime error after the following steps... Any idea on what went wrong here?

  1. Set up a new master-detail app for iPhone.
  2. Run the app as is -- No problems yet.
  3. Add the override method to the MasterViewController:
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        view.backgroundColor = UIColor.redColor()
        return view
    }
  1. Run app -- Crashes in AppDelegate, saying that it "can't add self as subview":

2016-06-06 06:54:11.485 TableViewDelegateDemo[16387:2390111] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't add self as subview' *** First throw call stack: ( 0 CoreFoundation 0x0000000107aa0d85 exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000109844deb objc_exception_throw + 48 2 CoreFoundation 0x0000000107aa0cbd +[NSException raise:format:] + 205 3 UIKit 0x000000010837fb37 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 122 4 UIKit 0x00000001083f1997 -[UITableView _addSubview:positioned:relativeTo:] + 76 5 UIKit 0x00000001083a887f -[UIScrollView(UIScrollViewInternal) _addContentSubview:atBack:] + 376 6 UIKit 0x00000001083fc453 -[UITableView _addContentSubview:atBack:] + 273 7 UIKit 0x00000001083f9b7b -[UITableView _updateVisibleHeadersAndFootersNow:] + 3143 8 UIKit 0x00000001083fb1d4 -[UITableView _updateVisibleCellsNow:isRecursive:] + 4153 9 UIKit 0x000000010842f686 -[UITableView _performWithCachedTraitCollection:] + 92 10 UIKit 0x0000000108416344 -[UITableView layoutSubviews] + 224 11 UIKit 0x0000000108383980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703 12 QuartzCore 0x000000010cd4ec00 -[CALayer layoutSublayers] + 146 13 QuartzCore 0x000000010cd4308e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366 14 QuartzCore 0x000000010cd42f0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 15 QuartzCore 0x000000010cd373c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277 16 QuartzCore 0x000000010cd65086 _ZN2CA11Transaction6commitEv + 486 17 QuartzCore 0x000000010cd657f8 _ZN2CA11Transaction17observer_callbackEP19CFRunLoopObservermPv + 92 18 CoreFoundation 0x00000001079c5c37 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23 19 CoreFoundation 0x00000001079c5ba7 __CFRunLoopDoObservers + 391 20 CoreFoundation 0x00000001079bb11c CFRunLoopRunSpecific + 524 21 UIKit 0x00000001082c3f21 -[UIApplication _run] + 402 22 UIKit 0x00000001082c8f09 UIApplicationMain + 171 23 TableViewDelegateDemo 0x00000001078b2532 main + 114 24 libdyld.dylib 0x000000010a30892d start + 1 25 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

4 Answers

Tyler Harris
Tyler Harris
5,322 Points

Pasan Premaratne Yes, it's still broken when you update the settings and apply Xcode fixes.

One error remains:

Value of type UIViewController has no member topViewController 

I fixed it using Stack Overflow(http://stackoverflow.com/questions/32815337/value-of-type-uiviewcontroller-has-no-member-topviewcontroller-after-xcode-7-upd ) and changing this line of code as follows:

self.detailViewController = (controllers[controllers.count-1] as! UINavigationController)
                .topViewController as? DetailViewController
Pasan Premaratne
STAFF
Pasan Premaratne
Treehouse Teacher

Hey all,

Is it still broken if you update the settings?

Eric Aichele
Eric Aichele
4,710 Points

I ran the update and I'm getting two errors. Screenshot

Scott Crocker
Scott Crocker
5,936 Points

I got a few errors as well trying to run the project included in downloads(although not the same errors as you did).

As Pasan states in the video it's just a master view template, so you can just go to File > New > Project and select Master Detail Application and it'll be pretty much the same thing.