XCode7.0: Insert Button Not Responding

There’s a ‘workaround’ answer and a ‘real’ answer to the problem.

Workaround first:

In AppDelegate.m, add the subviews to self.window.rootViewController.view instead of self.window:

[code] // Add our three UI elements to the window

[self.window.rootViewController.view addSubview:self.insertButton];

[self.window.rootViewController.view addSubview:self.taskTable];
[self.window.rootViewController.view addSubview:self.taskField];

// [self.window bringSubviewToFront:self.insertButton];[/code]

You can also get rid of the bringSubviewToFront: call, as I did above.

The real answer to the problem is this:

This chapter was designed to just tease a bit about iOS development. We have a whole book about real iOS development. In order to keep the chapter brief, we avoided the use of view-controller-based architecture for this chapter’s app, leaving discussion of view controllers and how they work for the actual iOS Programming Guide. Since then, iOS has come to require view-controller-based architecture, and now crashes your app if you don’t use view controllers, as you experienced.

The fallout is that while the workaround I mentioned will cause the app to build and run without crashing, the reality is that this chapter needs to be rewritten to use the more modern and correct patterns/paradigms, such as view controllers and autolayout.

Since you’re learning Objective-C right now, I suspect your goal is to then move on to iOS development. Any iOS book worth it’s mettle will cover those topics in detail.

The takeaway is to enjoy this chapter as a brief foray into iOS development, but not to treat it as a correct or modern approach to iOS development.

I hope that helps.

3 Likes