< Back

I Copied and Pasted a Controller in IOS Storyboard and It Wrecked Me

Lately, I’ve been working on an iOS app that runs on both iPad and iPhone. In Xcode, each device has it’s own dedicated Storyboard, so throughout development, I typically copied changes from one Storyboard to the next.

The Problem

One day, I need to build a new screen complete with a table view. So, instead of a dropping in a new view controller object in Storyboard and adding the necessary controls, I decided to copy and paste another controller that had most of the stuff I needed. The controller I happened to copy extended UITableViewController. After I pasted the view controller, I linked it up the new UIViewController class I was building. That class extended UIViewController with a tableView as an outlet. Unknowingly, I continued development and everything seemingly worked.

A few days later I came back to that view and needed to add multi-select behavior and wire in a UIToolbar that provides editing and deletion options. I dropped the toolbar on the controller in Storyboard, built the project, and it appeared like it should. I continued wiring up the toolbar buttons, tested and archived the build, and sent it out for external validation. To my complete surprise, the toolbar had disappeared.

The Cause

The toolbar continued to behave sporadically — I would make a settings change in Storyboard and it would somtimes appear and sometimes not. I changed the layout, modified styles, removed and re-added that toolbar control, and nothing seemed to work. It clearly was a bug Apple had released in UIKit or Storyboard. I then tried removing it entirely and generated the control from code, and it still misbehaved. Although, that approach did reveal part of source issue. The toolbar, after being added to the subview of self.view, looked stuck in the tableView’s heirarchy and sitting in the table’s parent view’s layout. I then switched back to the Storyboard controller, clicked on the tableView, looked at the outlets, and voila, there it was:

As you can see, the tableView was also outletted with the parent view of the class. Since I wasn’t using a UITableViewController, this caused all sorts of weird behavior. After a solid day of debugging, a simple copy and paste was the main culprit behind what I thought was a sophisticated error deep in Apple’s source code.

Connect with us

Thank You!

We really appreciate your interest in what we do.

We'll get back to you as soon as we can.